如何通过php脚本编辑crontab?

时间:2017-08-30 10:58:28

标签: php shell cron

我有一个使用PHP脚本写入crontab的函数:

function changejob() {
global $existingJobs;
global $newJob;
chmod("/tmp/crontab", 0764);   
if (file_put_contents('/tmp/crontab', $newJob.PHP_EOL)) {
    if (exec('crontab /tmp/crontab')) { 
        echo 'Crontab changed to ' .$newJob;    
    }
    else {
        echo 'Error with exec command';
    }
}
else {
    echo 'file_put_input function failed';
}

}

该脚本与exec命令'回应“错误”。 如果我立即在命令行中运行crontab / tmp / crontab,则会正确编辑crontab文件。所以我知道file_put_contents函数工作,而echo exec()函数没有。

启用了错误报告,但未报告任何内容。

0 个答案:

没有答案
相关问题