How to setup a cron
Cron jobs allows you to schedule tasks regularly.
There are two types of cron job. System jobs and individual user jobs
System jobs
These are controlled with the file /etc/crontab. You won’t find the actual scripts that run here, you will find these under the following folders:
/etc/cron.hourly/
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/
Jobs of individual users
These are stored in a the /var/spool/cron/tabs/ folder. These can be edited with the crontab command
crontab -e Creates or edits a cron job
crontab file Specifies a file containing a list of jobs
crontab -l Displays current jobs
crontab -r Deletes all jobs
Scheduling
Write a script and save to a directory
Now use the following command:
crontab [-u user] [-] [-e | -r] [file to run]
Or log on as that user and do the following:
1. Type “crontab -e” at the command prompt
2. Edit the file as needed (it uses “vi”)
You will need at least 6 fields for a simple cron job.
——————————————————————————————————————
Minutes Hours Day of the month Month Weekday Command
30 13 * * 1 command
——————————————————————————————————————-
Examples:
To get a job to run at 13:30 every Monday type the following
30 13 * * 1 /root/command.sh
To get the command to run every 1st of the month type the following:
30 13 1-12 * /root/command.sh
To get a job to run every 10 minutes from 8 to 5, 5 days a week, type the following:
*/10 8-17 * * 1-5 /root/conmmand.sh
You can also set a script or command to run when the computer boots up
@bootup /scripts/firewall.sh