[plug] automating tasks
Ryan
ryan at prodigital.net.au
Wed Jan 16 01:16:53 WST 2002
>If I wanted to,say execute a command on a daily basis like "vacuumdb -a"
>at 3.21am, how would I do this?
>
>What if I wanted to restart a daemon on a weekly basis?
Firstly have a look at: man 5 crontab
That should be all I need to say :) however if you are feeling lazy or it
is too early in the morning, read the rest ...
Once you have that under your belt, have a look at your /etc/crontab file,
it, along with the crontab(5) manpage should have enough examples to get
you going, the first comment line says it all:
#m h dom mon dow user command
25 6 * * * root test -e /usr/sbin/anacron || run-parts --report
/etc/cron.daily
47 6 * * 7 root test -e /usr/sbin/anacron || run-parts --report
/etc/cron.weekly
52 6 1 * * root test -e /usr/sbin/anacron || run-parts --report
/etc/cron.monthly
So to do what you asked in a crude and non-error checking way:
21 3 * * * foo vacuumdb -a
01 6 * * 7 root /etc/init.d/some_service restart
Alternatively for the weekly one you can create an executable script in
/etc/cron.weekly/ - cron will execute all scripts in that directory on a
weekly basis as stated in the crontab file example above (6:47AM on the 7th
day of the week). Likewise for the daily script if you don't want to
control the EXACT time it gets run at.
If the commands you run output to STDOUT, that output will normally get
emailed to you. If you don't want this you can redirect the command to
/dev/null and then you'll only get emailed drastic STDERR stuff.
And remember to restart cron once you've made changes.
HTH,
Ryan
More information about the plug
mailing list