简体   繁体   English

使用php脚本更新crontab文件

[英]update crontab file using php script

I have to create a crontab file using php script.This is my code : 我必须使用php脚本创建一个crontab文件。这是我的代码:

<?php
file_put_contents('/tmp/crontab.txt','* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
?>

the file crontab.txt is created.But the next command 'crontab /tmp/crontab.txt' is not executed.When I type the command 'crontab -l',i get the output : 'no crontab for root'.But when I manually execute the command in terminal,the crontab is installed correctly.Why cant I execute the same command using my php script? 创建了文件crontab.txt。但是没有执行下一个命令'crontab /tmp/crontab.txt'。当我输入命令'crontab -l'时,我得到输出:'no crontab for root'.But when我在终端手动执行命令,正确安装了crontab。为什么我不能使用我的php脚本执行相同的命令?

The server is not (should not be) running as root. 服务器不是(不应该)以root身份运行。 Check the crontab for the HTTPd user (on debian/ubuntu running Apache, it's www-data ). 检查HTTP用户的crontab(在运行Apache的debian / ubuntu上,它是www-data )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM