Scheduling jobs using crontab and at in Debian linux
Scheduling job with crontab command
The crontab commands work by reading a crontab file. A crontab file is a plain text file that list all the job you have to scheduled. Each line of the file consists of command with all its options and arguments, date and time to run it.
There are two files to control access to crontab
/etc/cron.allow : only user listed can access the crontab
/etc/cron.deny : listed users are denied for crontab
Format of crontab file:
***** Command to be executed
first field is for Min (0-59)
second field for Hour (0-23)
third field for Day of month (1-31)
Fourth field for month (1-12)
Fift field for Day of week (0-6, where 0 is Sunday)
The last field is command to be executed
Edit the crontab file
To edit crontab file, use crontab -e
Consider the following example
Suppose we want to run alaram script everyday at noon, according to the task we have to edit crontab file
Follow the steps
# crontab -e
It will directly open the file in vi editor. Edit the following to run alaram script everyday at noon
0 12 *** /usr/share/bin/alaram
save and quit
This will run alaram script evryday at 12 noon.
Scheduling task with at command
We can use at command to schedule a command or script to run at single time
Root user can use two files to allow or not allow the user , at command
/etc/at.allow – will allow user to run the at command
/etc/at.deny – will deny user to use at command
Command syntax
at TIME [DATE]
at command options
-c task : Display the listed task
-d task : Delete the specific task
-f file : Read task from file entered
-l : list schedule task for current user
at command time format
day – set the day of week
hh:mm – sets the time
mmddyy – sets the date
now – runs the command immediately
tomorrow – Runs the command tomorrow
Example of at command
# at -f mycrontest.sh 10pm tomorrow
This command will run the script mycrontest.sh tomorrow at 10 pm

Leave a Reply