2

For example I have a cron running on the 1st of every month, this cron executes a PHP script that returns some dates.

I want to use these dates and modify the schedule of another cron job?

I know I can add a new cronjob doing something like this but unsure of how to update 1 specific entry when there could be multiple.

$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
Kyle
  • 577
  • 3
  • 22

1 Answers1

1

Make sure you do not break something you better monitor your cronjobs after you deploy this But what you want to do is possible.

  1. You can create, modify and delete Cronjobs via PHP (Use PHP to create, edit and delete crontab jobs?)

  2. This is also true if this PHP is executed via another cronjob (as long as you give the correct permissions)

⇒ It is possible (q.e.d.)

Also see this question: https://askubuntu.com/questions/408611/how-to-remove-or-delete-single-cron-job-using-linux-command

This is how you remove a single cronjob (by example) - just create a new one for the different dates:

crontab -u mobman -l | grep -v 'perl /home/mobman/test.pl'  | crontab -u mobman -
Blackbam
  • 12,200
  • 19
  • 71
  • 117