crontab定时任务, 定时到秒
crontab定时任务最小支持到minute, 定时到秒执行的任务, 写起来比较麻烦
* * * * * /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt 2>&1
-
/bin/sh 任何定时任务都必须要写上命令的绝对路径; 查看命令的路径命令:type [command]
-
定时任务本身就是后台运行
-
1: 屏幕输出; 2: 标准定向输出
下面的任务为每隔5秒执行一次任务:
* * * * * sleep 5; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 10; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 15; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 20; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 25; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 30; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 35; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 40; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 45; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 50; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
* * * * * sleep 55; /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt
即睡5秒执行一次, 必须是60秒的整约数, 这是最好的定时到秒执行任务的方法. 其它方法都有可能出现问题.