Is it possible to use PHP to create, edit and delete crontab jobs?
I know how to list the current crontab jobs of the Apache user:
$output = shell_exec('crontab -l');
echo $output;
But how to add a cron job with PHP? 'crontab -e' would just open a text editor and you will have to manually edit the entries before saving the file.
And how to delete a cron job with PHP? Again you have to manually do this by 'crontab -e'.
With a job string like this:
$job = '0 */2 * * * /usr/bin/php5 /home/user1/work.php';
How do I add it to the crontab jobs list with PHP?
crontab command usage
So,
The above can be used for both create and edit/append provided the user has the adequate file write permission.
To delete jobs:
Also, take note that apache is running as a particular user and that's usually not root, which means the cron jobs can only be changed for the apache user unless given
crontab -u
privilege to the apache user.