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?

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

I dont think that is the problem as I can execute 'crontab -l' command using same php script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.