我已經將cron作業添加到/etc/crontab文件在php腳本中的方法file_put_contents但是這個cron沒有執行。如果我將這個文件保存在nano編輯器中,cron是可以工作的。可以promtp爲什麼被php腳本添加的cron沒有執行? 我嘗試重新加載cron守護進程,但這沒有幫助。 我使用文章http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html的cron類。Cron從PHP腳本不工作
1更換方法saveJobs用於保存crons到文件/etc/crontab中。
static public function saveJobs($jobs = array()) {
$output = file_put_contents('/etc/crontab', self::arrayToString($jobs));
return $output;
}
命令添加cron是添加
Crontab::addJob("*/1 * * * * root php -f /var/www/get_all_clients_data_db.php ");
紀錄cron來的crontab但這cron的不執行。
/etc/crontab中
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd/&& run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.daily)
47 6 * * 7 root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.weekly)
52 6 1 * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.monthly)
#
*/1 * * * * root php -f /var/www/get_all_clients_data_db.php
我的錯誤道歉。這是我在StackOverflow上的第一個問題。 在此先感謝。
顯示你的結果。你的腳本工作後你會得到什麼。之後也顯示'ls -la/etc/crontab'。 – ksimka
請分享您的代碼。沒人能猜到你想要做什麼。 – Repox
fil_put_contents必須是file_put_contents – schellingerht