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