Category: Scheduled Tasks

How to setup a cron

By peter, September 12, 2009

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

Using the AT command

By peter, September 11, 2009



at will allow you to run a task once at a specified time If the at service is not running type “rcatd start”. Once the “AT” service is running the, Type the command at followed by the time at the command prompt as follows:

at 14:30

You will then be taken into the “at” command to type in the command you want to execute. Once you have added in the commands you want to execute, type “Ctrl d” to quit. To remove an “at” job, type “atrm” followed by the job number. To view scheduled jobs type “atq” at the command prompt.

OfficeFolders theme by Themocracy