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秒的整約數, 這是最好的定時到秒執行任務的方法. 其它方法都有可能出現問題.