Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Another of the most useful tools in server administration is the Crontab – you use this to schedule jobs (programs) to run at regular intervals.
These tasks can be varied, from restarting servers, services – creating files, changing permissions, runing batch programs, deleting files etc…
Of course sometimes crontab is not the best solution as it can have several problems – in which case other choices are available – including writing your own – however we will cover that another time.
First a coouple of facts about cron:
Generally to edit the crontab – which is where you would add things to run type in “crontab -e” – this will open it in your system editor (vim is my choice, but others can be used).
you will probably see some content – similar to this:
1 0 * * * shutdown -r now
This means that at one minute past midnight the server will reboot (execture the immediate shutdown and restart command with no delay) each day. The * are wildcards saying that the instruction should run no matter the criteria of that column (if it’s all * then it will run each minute).
The fields are the following: I recommend pasting this in the top of your crontab file – the # at the start mean it will ignore the entries.
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * *
Remember if the program has output you can store it in a file the same as you can on the command line – just type ” > /var/log/logfile”
in the entry after the command and it will log output to the file in question.