我知道我可以在Linux系统中使用date +%s和stat。
但是由于Solaris不支持这些格式或命令,我如何创建一个those脚本来比较文件修改时间和当前时间?
与当前时间相比,修改文件的时间应在10分钟之内。
[ShellScript]
Current_Time=
Modification_Time=
Compare = Current_Time - Modification_time
if ["$Compare" -gt 600]; then
Echo "there is no find found within 10 min"
else
Ech
我对Linux Shell脚本编程非常陌生,不知道是否有人可以帮助我完成以下工作。
我创建了一个脚本来与我的linux机器同步时间,但似乎只有一个exec命令完成
#!/bin/bash
#Director SMS Synch Time Script
echo The current date and time is:
date
echo
echo Synching GTS Cluster 1 directors with SMS.
echo
echo Changing date and time for director-1-1-A
exec ssh root@128.221.252.3
我想在bash中尽可能快地比较两个Unix/Linux时间戳:
TIMESTAMP_A=1472680800
TIMESTAMP_B=1458687600
if [[ ${TIMESTAMP_A} -lt ${TIMESTAMP_B} ]]; then
echo "Timestamp A is younger!";
else
echo "Timestamp B is younger!";
fi
我的解决方案总是有效的吗?还是我需要处理一些特殊情况?
目前,我正在使用Vim编写一个在Linux上的学校作业,其中我必须编写一个脚本来显示当前登录的用户、时间和日期,并且只列出网卡的IP地址。除了IP地址部分,我什么都能用。如果有人能帮忙,我会非常感激的。
编辑以包含我目前拥有的代码。
#!/bin/bash
Time=$(date)
IP=$(ifconfig ens33)
echo "The following user is currently logged in $USER"
echo ""
echo "The current time is $Time"
echo ""
e
我正在服务器上的php文件中尝试linux命令,用于正常运行时间,如下所示
<p> The uptime for this system is <?php $up_time=shell_exec('uptime');
echo $uptime; ?</p>
但是当我打开我的网页时,它只显示:
The uptime for this system is
PHP似乎没有运行该命令。如果我转到命令提示符并运行正常运行时间,我确实会看到结果。
我正在对Linux ssh服务器执行ssh操作。php文件驻留在服务器上的我的文件夹中。
我有一个简单的bash脚本
#!/bin/bash -x
for line in `tail /home/user/line`
do
echo $line
done
但是不知道为什么它会回响所有的单词,而不是下面的每一行都是输出。
++ tail /home/user/line
+ for line in '`tail /home/user/line`'
+ echo Linux
Linux
+ for line in '`tail /home/user/line`'
+ echo is
is
+ for line in '`tail
#!/bin/bash
clear
echo "Wishing according to Time of the PC"
h=$(date '+%H') #This line works, I've Checked.
if test $h -gt 6 -a $h -lt 12
then
echo "Good Morning"
elif test $h -gt 12 -a $h -lt 16
then
echo "Good Afternoon"
elif test $h -gt 16 -a $h -lt
我希望这里有人能帮我解决这个奇怪的问题。
我想我知道为什么会发生,但我不知道如何解决。可能是因为BIOS时间设置不正确或类似的原因。但我不想更改近似400+服务器的BIOS时间。(或更改BIOS批处理)
root@spool:~# echo TEST > /dev/kmsg
root@spool:~# dmesg -T | tail -1
[Mon Feb 17 04:57:03 2014] TEST
root@spool:~# date
Mon Feb 17 11:45:17 CET 2014
服务器正在运行ntp以实现时间同步。
这里有人知道如何在操作系统中解决这个问题吗?
Linu
我正在试图找出如何创建一个新文件夹,该文件夹将日期而不是时间附加到目录名的末尾。我只需要现在的创造时间,仅此而已。
尝试用一些非常基本的东西,如下面的例子.
if exists CNC_%date% goto EXIST
if not exists CNC_%date% goto CREATE
:CREATE
mkdir CNC_%date%
:EXIST
echo Folder already exists!
echo Check directory and rename it to prevent loss of data.
echo.
echo Press any key
我在这里使用的是嵌入式linux,我需要根据键盘给出的用户输入将当前的日期设置为系统,这里我失败了,在一个条件下,系统必须等待2分钟,un才能从键盘获得输入,如果达到指定的等待时间,则必须从循环中出来.
下面是我的代码:
echo please enter the date in below format
echo YEAR- MM-DD HRS:MNS:SEC and press enter
read -e a1
startd=$(date -s "$a1");
echo "$startd";
hwclock --systohc
date
目标:我正试图在一个预定的时间安排一个“码头工”。
操作系统: Linux Ubuntu 18.04
我曾尝试在linux中使用'at‘命令,但我试图设置变量,但无法使其正常工作。
以下尝试:
sudo echo "KEY='VALUE' DIRECTION='D' sh run.sh" | at now + 2 minute
# Above does not run the docker-compose
sudo echo "KEY='VALUE' DIRECTION='D' sh run.sh
我想检查主机名,以确保它们符合Bash Shell中的标准命名约定。
假设主机名是ab-cde-01
wolf@linux:~$ h='ab-cde-01'
wolf@linux:~$ echo $h
ab-cde-01
wolf@linux:~$
我一开始就构建了if else循环,它运行得很好。
wolf@linux:~$ if [ $h = 'ab-cde-01' ]; then
> echo $h is a valid name
> else
> echo $h is an INVALID name
> fi
ab-cde-01