I want to edit crontab from PHP script.
$output = shell_exec('crontab -l');
echo "<pre>";
print_r($output);
echo "</pre>";
This is returned.
MAILTO="[email protected]"
*/2 * * * * /usr/bin/php5 /var/www/vhosts/example.com/streaming.example.com/index.php admin cron > /dev/null
MAILTO=""
*/1 * * * * /opt/psa/admin/sbin/fetch_url 'https://www.example.com/referral/send_referral_email'
MAILTO=""
*/5 * * * * /opt/psa/admin/sbin/fetch_url ' https://www.example.com/members/send_notif'
MAILTO="[email protected]"
*/2 * * * * /usr/bin/php5 /var/www/vhosts/example.com/streaming.example.com/index.php admin cron3 > /dev/null
One of the scripts https://www.example.com/members/send_notif
should be running every five minutes but isn’t. I see there is a space before the https and i think that might be the cause. How do i edit? I haven’t got access to cpanel, so i have to do from PHP.
3
Answers
Found out how to do it.
Try something like:
Once you have the output of crontab, make the required change in the variable and then write it to a file:
Then write the new content to crontab: