Sunday, November 25, 2012

Job Automation



Job Automation
In Linux, tasks can be configured to run automatically within a specified period of time, on a specified
date, or when the system load average is below a specified number. Red Hat Enterprise Linux is preconfiguredto run important system tasks to keep the system updated. A system administrator can use automatedtasks to perform periodic backups, monitor the system, run custom scripts, and more.
Red Hat Enterprise Linux comes with several automated tasks utilities: crontab, at.
Crontab
Crontab  is a daemon that can be used to schedule the execution of recurring tasks according to acombination of the time, day of the month, month, day of the week, and week.

Service profile
Service: crond
Package: crontab
Configuration file: /etc/crontab
                                 /etc/cron.deny
                               /etc/cron.allow
Objective :To schedule a job
Install the package
[root@raju~]#yum install crontab* -y
Configuring Cron Tasks
To create new task we use crontab -e
[root@raju~]#crontab –eu username
minute        hour    day                month             dayofweek            command
minute — any integer from 0 to 59
hour — any integer from 0 to 23
day — any integer from 1 to 31 (must be a valid day if a month is specified)
month — any integer from 1 to 12 (or the short name of the month such as jan or feb)
dayofweek — any integer from 0 to 7, where 0 or 7 represents Sunday (or the short name of the week such as sun or mon)

You can see a list of active crontab entries by entering the following terminal command:
crontab -l     
You can remove crontab entries by entering the following terminal command:
crontab -r     



NOTE:The crontab that you created with the crontab command is stored in /etc/spool/cron under the name of the user who created it. So the above crontab is stored in /etc/spool/cron/ian
In addition to the user crontab files in /var/spool/cron, cron also checks /etc/crontab and files in the /etc/cron.d directory. These system crontab have one additional field between the fifth time entry (day) and the command. This additional field specifies the user for whom the command should be run, normally root
Controlling Access to Cron
T he /etc/cron.allow and /etc/cron.deny files are used to restrict access to cron. The format of both access control files is one username on each line. Whitespace is not permitted in either file.
 Examples
 [root@raju~]#crontab –eu koti    #will create task for user koti
10   20  *  8  *  /usr/bin/free
[root@raju~]#chkconfig crond on
[root@raju~]#service crond restart
[root@raju~]#crontab –l koti     # will list the job schedules of user koti
[root@raju~]#vi /etc/cron.deny
Shiva      #deny cronjobs access to user shiva

At job
While cron is used to schedule recurring tasks, the at command is used to schedule a one-time task at a specific time
Service profile
Service: atd
Package: at
Configuration file: etc/at.deny
                               /etc/at.allow
Objective:To schedule a job at specified time
Install the package
[root@raju~]#yum install at* -y

T o schedule a one-time job at a specific time, type the command at time, where time is the time to execute the command.
The argument time can be one of the following:
HH:MM format — For example, 04:00 specifies 4:00 a.m. If the time is already past, it is executed at
the specified time the next day.
midnight — Specifies 12:00 a.m.
noon — Specifies 12:00 p.m.
teatime — Specifies 4:00 p.m.
month-name day year format — For example, January 15 2002 specifies the 15th day of January in the year 2002. T he year is optional.
MMDDYY, MM/DD/YY, or MM.DD.YY formats — For example, 011502 for the 15th day of January in the year 2002.
now + time — time is in minutes, hours, days, or weeks. For example, now + 5 days specifies that the command should be executed at the same time five days from now.

After typing the at command with the time argument, the at> prompt is displayed. T ype the commandto execute, press Enter, and type Ctrl+D. Multiple commands can be specified by typing eachcommand followed by the Enter key. After typing all the commands, press Enter to go to a blank lineand type Ctrl+D.
Options
-f Read the commands or shell script from a file instead of specifying them at the prompt.
-m Send email to the user when the job has been completed.
-v Display the time that the job is executed.
-l to list the jobs that are scheduled
Controlling Access to at
The /etc/at.allow and /etc/at.deny files can be used to restrict access to the at commands.
Examples
[root@raju~]#at 10:30   #will schedule following jobs at 10:30
At>date
At>hostname
At>ctl+D

Stay Connected With Free Updates!

Subscribe via Email

Follow me!

Leave Your Comment Below If You Like This Post

0 comments: