I want to be able to programatically add a new cron job, what is the best way to do this?
From my research, it seems I could dump the current crontab and then append a new one, piping that back into crontab:
(crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -
Is there a better way?
To Add something to cron
To remove this from cron
hope would help someone
also you can add your tasks to /etc/cron.*/
OP's solution has a bug, it might allow entries to be added twice, use below to fix.
If you're planning on doing it for a run-once scenario for just wget'ing something, take a look at 'at'
Most of the solutions here are for adding lines to the crontab. If you need more control, you'll want to be able to control the entire contents of the crontab.
You can use piping to do this pretty elegantly.
To completely rewrite the crontab, do
This should be easy to combine with other answers described here like
Or, if you have the contents in a file, it is even simpler
man crontab is also useful:
CRONTAB(1)
NAME
SYNOPSIS