0

I have to create a crontab file using php script.This is my code :

<?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?

thomas
  • 27
  • 1
  • 1
  • 5

1 Answers1

2

The server is not (should not be) running as root. Check the crontab for the HTTPd user (on debian/ubuntu running Apache, it's www-data).

Kryten
  • 15,230
  • 6
  • 45
  • 68
  • I dont think that is the problem as I can execute 'crontab -l' command using same php script. – thomas Mar 31 '14 at 17:48