crontab定時任務, 定時到秒


crontab定時任務最小支持到minute, 定時到秒執行的任務, 寫起來比較麻煩

* * * * * /bin/sh /home/jiewang/portraitProc/test.sh >> /home/jiewang/portraitProc/test.txt 2>&1

  1. /bin/sh 任何定時任務都必須要寫上命令的絕對路徑; 查看命令的路徑命令:type [command]

  2. 定時任務本身就是后台運行

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM