秒級定時任務
阿新 • • 發佈:2020-12-19
技術標籤:shell
crontab編寫
原理多個命令列用sleep執行產生間隔效果
路徑 /root/script/test.php
<?php
file_put_contents('/root/script/php/crontab/run.log', date('Y-m-d H:i:s')."\r\n", FILE_APPEND);
?>
PHP
Copy
creontab -e
* * * * * php /root/script/test.php * * * * * sleep 10; php /root/script/test.php * * * * * sleep 20; php /root/script/test.php * * * * * sleep 30; php /root/script/test.php * * * * * sleep 40; php /root/script/test.php * * * * * sleep 50; php /root/script/test.php
Bash
Copy
建立日誌目錄 /root/script/php/crontab
檢視結果tail -f /root/script/php/crontab/run.log
指令碼方式
方法二:寫shell指令碼 /home/mytest/test_control.sh
step=5
i=0
while i<=60
do
echo /bin/sh home/mytest/test.sh
i+=$step
sleep()
done
Bash
Copy
然後在crontab 中設定:
*/1 * * * * /bin/sh /home/mytest/test_control.sh
本文為dahai原創文章,轉載無需和我聯絡,但請註明來自大海技術部落格https://www.ypyunedu.com