开发者

Unable to edit cron using PHP - no error

I am trying to replace the crontab using a new crontab stored at /tmp/crontab.txt.

  $output = '';
  $output .= "Existing Crontab contents:<br>";
  $output .= she开发者_StackOverflow中文版ll_exec('crontab -l');

  $output .= "<br>new contents:<br>";
  $output .= file_get_contents('/tmp/crontab.txt');

  $output .= "<br>Result of import:<br>";
  $output .= shell_exec('crontab /tmp/crontab.txt');
  $output .= shell_exec('crontab -l');
  echo $output;

The output is:

Existing Crontab contents:
1 2 3 4 5 existing
new contents:
* * * * * echo 'test'
Result of import:
1 2 3 4 5 existing 

You can see the import does not work and does not show an error.

Apache is running as 'nobody'. I have tried crontab -u nobody /tmp/crontab.txt as root and it works.

Is this a permissions issue? If so, why is php (running as nobody) unable to update it's own cron? How do I get around this?

Thanks


Try changing your import line to this:

$output .= shell_exec('crontab /tmp/crontab.txt 2>&1');

that'll redirect stderr to stdout and let PHP catch any error message cron's spitting out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜