[英]Cron Job status check by code
我們的系統中有多個Cron,某些Cron依賴於父Cron,但有時父Cron停止了,而不是所有子Cron無法正常工作。 如果cron作業停止工作,則服務器可能會將郵件發送到用戶電子郵件或顯示任何其他警報,這有可能。
您可以解析crontab -l
的輸出,以查看是否存在特定的crontab條目。 至於cron是否正在運行,您可以解析ps -eaf
命令的輸出以查看crond是否正在運行。
您可以在PHP中使用system()
函數來調用命令行工具或exec()
。
例如:
exec("PATH=/usr/sbin:/usr/bin:/sbin:/bin; service crond status", $output, $return);
print $return . "n";
可能是您可以在其他服務器上運行Monitor-Cron來監視其他Cron的運行狀況。 有幾種監視方式:
1) Your parent cron could set a flag in database to indicate its running state.
2) Your monitor cron could read output of "ps -eaf" command to check if parent cron is running or not
首先,您的monitor-cron應該檢查運行父cron的服務器是否可用。
問候,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.