1.Linux下用shell获取指定文件的最后修改时间并与系统时间比对,如果相差时间超过3分钟则执行另一个脚本
a=`stat -c %Y filename`;b=`date +%s`;if [ $[ $b - $a ] -gt 180 ];then command;else othercommand;fi就挺好的
但是你要注意在crontab中执行的时候需要加source一下环境变量,不然有些命令会找不到路径。
如:
0-59 * * * * . /etc/profile;a=`stat -c %Y filename`;b=`date +%s`;if [ $[ $b - $a ] -gt 180 ];then command;else
othercommand;fi
. /etc/profile可以换成你用户目录下的配置文件.
C shell的为 .cshrc 在用户主目录下
bashell的为 .bashrc 在用户主目录下
kshell的为.profile 在用户主目录下
2. Linux脚本判断文件修改时间小于等于系统当前时间5分钟输出1,否则输出0
if [ -z `find /usr/123.txt -mmin -5` ];then
echo 0
else
echo 1
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22569416/viewspace-1873771/,如需转载,请注明出处,否则将追究法律责任。