linux中crontab实现以秒执行任务

很多时候,我们计划任务需要精确到秒来执行,根据以下方法,可以很容易地以秒执行任务。

以下方法将每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