PDA

View Full Version : Adding to the crontab, from a Makefile.



f0rmula
April 1st, 2007, 06:03 PM
Is there an easy way to append to the crontab from within a Makefile?

doing '$crontab newcronjob' replaces the crontab entirely.

So far, I'm planning on doing:

$crontab -l > cronfile
$echo "0 * * * * /bin/whatever" >> cronfile
$crontab cronfile
$rm cronfile

I realise this is rather grim. Please tell me there's a easier (and probably obvious) way I don't know about. :)

James

foxylad
April 4th, 2007, 07:23 AM
Yes - it's much easier to put a file in the /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly directories. Anything in these directories will be run at the relevant time.

Enjoy!
FoxyLad.

kpatz
April 4th, 2007, 04:28 PM
If you want more precise control than offered in cron.hourly etc., such as running at specific times or as a specific user, you can create a file in /etc/cron.d containing your crontab entries.

The format for files in /etc/cron.d are different than regular crontabs. In particular there is a user field after the times and before the command. So instead of:
0 * * * * /bin/whateveryou'd have
0 * * * * root /bin/whatever (if you want the program to run as root).