【发布时间】:2021-08-03 23:08:46
【问题描述】:
我想使用 Shell 脚本每 5 秒运行一次 php 文件。但有时脚本会每秒运行一次,有时会停止运行。我还需要使用 crontab 吗?请帮忙。
#!/bin/bash
while true; do
begin=`date +%s`
php /home/user/www/run.php
end=`date +%s`
if [ $(($end - $begin)) -lt 5 ]; then
sleep $(($begin + 5 - $end))
fi
done
【问题讨论】:
-
据我了解,linux cron 可以在 Minutes、Hours、Days、Months 中运行,但
NOT秒。你应该使用你的 shell 脚本和nohup在后台运行它