很多时候,我们计划任务需要精确到秒来执行,但linux最小只支持分钟,很多linux自带的版本都不直接支持以秒来执行,根据以下方法,可以很容易地以秒执行任务。
crontab每秒执行,cron running every second
以下方法将每10秒执行一次
1、编辑crontab
crontab -e
* * * * * /bin/date >>/tmp/date.txt
* * * * * sleep 10; /bin/date >>/tmp/date.txt
* * * * * sleep 20; /bin/date >>/tmp/date.txt
* * * * * sleep 30; /bin/date >>/tmp/date.txt
* * * * * sleep 40; /bin/date >>/tmp/date.txt
* * * * * sleep 50; /bin/date >>/tmp/date.txt
2.、检查结果
tail -f /tmp/date.txt
Fri Jul 8 12:44:41 CST 2011
Fri Jul 8 12:45:01 CST 2011
Fri Jul 8 12:45:11 CST 2011
Fri Jul 8 12:45:21 CST 2011
Fri Jul 8 12:45:31 CST 2011
Fri Jul 8 12:45:41 CST 2011
Fri Jul 8 12:45:51 CST 2011
Fri Jul 8 12:46:01 CST 2011
Fri Jul 8 12:46:11 CST 2011
Fri Jul 8 12:46:21 CST 2011
Fri Jul 8 12:46:31 CST 2011
Fri Jul 8 12:46:41 CST 2011
Fri Jul 8 12:46:51 CST 2011
Fri Jul 8 12:47:01 CST 2011
Fri Jul 8 12:47:11 CST 2011
Fri Jul 8 12:47:21 CST 2011
说明:需要将/bin/date更换成你的命令即可
完成!
crontab每秒执行,cron running every second
以下方法将每10秒执行一次
1、编辑crontab
crontab -e
* * * * * /bin/date >>/tmp/date.txt
* * * * * sleep 10; /bin/date >>/tmp/date.txt
* * * * * sleep 20; /bin/date >>/tmp/date.txt
* * * * * sleep 30; /bin/date >>/tmp/date.txt
* * * * * sleep 40; /bin/date >>/tmp/date.txt
* * * * * sleep 50; /bin/date >>/tmp/date.txt
2.、检查结果
tail -f /tmp/date.txt
Fri Jul 8 12:44:41 CST 2011
Fri Jul 8 12:45:01 CST 2011
Fri Jul 8 12:45:11 CST 2011
Fri Jul 8 12:45:21 CST 2011
Fri Jul 8 12:45:31 CST 2011
Fri Jul 8 12:45:41 CST 2011
Fri Jul 8 12:45:51 CST 2011
Fri Jul 8 12:46:01 CST 2011
Fri Jul 8 12:46:11 CST 2011
Fri Jul 8 12:46:21 CST 2011
Fri Jul 8 12:46:31 CST 2011
Fri Jul 8 12:46:41 CST 2011
Fri Jul 8 12:46:51 CST 2011
Fri Jul 8 12:47:01 CST 2011
Fri Jul 8 12:47:11 CST 2011
Fri Jul 8 12:47:21 CST 2011
说明:需要将/bin/date更换成你的命令即可
完成!