Home > Unix > UNIX – Lesson 026 – Job and Job Scheduling – at and crontab commands

UNIX – Lesson 026 – Job and Job Scheduling – at and crontab commands


at
The “at” command is used to schedule a program to run at a specific time

Syntax :
at [-lrt]

Key argument :

  • -l   Reports all jobs scheduled
  • -r   Removes the jobs with the specified at_job_id   operands
  • -t MMddhhmm   Submits the job to be run at the time specified   by the time option-argument.

Example :
$ at -t 02261520
at> echo “Happy my dear Xarabas!“ > /tmp/Xarabas.txt
at> <EOT>
commands will be executed using /bin/csh
job 1204035720.a at Tue Feb 26 15:22:00 2008

#To exit from at command use “CONTROL+D”

$ at –l
1204035720.a    Tue Feb 26 15:22:00 2008
#To see the scheduled tasks

$ more /tmp/Xarabas.txt
Happy my dear Xarabas!

$ at -r 1204035600.a
# To cancel the scheduled task (the task number is 1204035600.a).

$ at –l

==================================================================================

crontab

The “crontab” command allows to schedule job’s execution periodically

Syntax :
crontab –l   list the content of the cronfile
crontab –e   enter in edit mode (you have to set the variable EDITOR, for example you can use “vi” editor) to change the cronfile

Cronfile consists of lines of six fields each. The first five items specify:

1. Min (0-59)
2. Hours (0-23)
3. Days of the month (1-31)
4. Months of the year (1-12)
5. Days of the week (0-6 with 0=Sunday)

An “*” indicates all legal values. Fields are separated by spaces or tabs. The last field is the program to be executed.

Example :

$ crontab –l

###########################################
#  Script to backup Databases                                           #
###########################################

#
00 01 * * 1-5  /data/s2sswd/backup/backup_GM_1_64_STCA.sh > /dev/null 2>&1
30 02 * * 1-5  /data/s2sswd/backup/backup_CM_2_64_STCA.sh > /dev/null 2>&1
#

########################################
# Script To Backup the registries on SUN_HP_01 Server  #
########################################

#
00 7 * * 1 /check/backup/backup_reg.sh  > /dev/null 2>&1
#

########################
# Script to check Samba daemon  #
########################

#
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /samba_daemon/samba.awk /samba_daemon/.test > /tmp/samba_ctrl.log
#
15 18 31 12 * /samba_daemon/test.awk  /samba_daemon/.test > /tmp/samba_ctrl.log
#

The first script (backup_GM_1_64_STCA.sh) will be executed every workday (1-5) at 07:00 AM.
The second script (backup_CM_2_64_STCA.sh) will be executed every workday (1-5) at 02:30 AM.
The third script (backup_reg.sh) will be executed only the monday (1) at 07:00 AM.
The fourth script (samba.awk) will be executed every 5 minutes (every day because we have “*” in the next fields)
The fifth script (test.awk) will be executed only the 31-12 at 18:15.

Advertisements
Categories: Unix

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: