Tuesday, September 11, 2012

In any operating system, it is possible to create jobs that you want to reoccur. This process, known as job scheduling, is usually done based on user-defined jobs. For Red Hat or any other Linux, this process is handled by the cron service or a daemon called crond, which can be used to schedule tasks also called jobs. By default, Red Hat comes with a set of predefined jobs that occur on the system(hourly, daily, weekly, monthly, and with arbitrary periodicity. As an administrator, however, you can define your own jobs and allow users to create them as well.
The importance of the job scheduling is that some times, we need to run some scripts, which check the free space in mount point. In this case, it will check the free space on hourly basis and send mail to respective user you want. In this case, we can't run script manually on hourly basis. To avoid this manual work, we are doing job scheduling by crontab.
Important files related to cron and at
/etc/crontab – The file which stores all scheduled jobs.
/etc/cron.deny – Restricted users(to run cron job) entry in this file.
/etc/cron.allow – allowed (to run cron job) users entry in this file.
/etc/at.deny – same as cron.deny for restricting at jobs.
/etc/at.allow – same as cron.allow for allowing user to user at jobs.
*             *            *            *            *   /Personal/Send_Status.sh
                                                          Day Of Week(0-6) (Sunday =0 or 7)
                                           Month (1-12) Jan, Feb, Mar…
                              Day Of Month (1-31)
                Hour(0-23)
Minute(0-59)


* -- is created as a wildcard. Meaning any possible value.
*/5 -- is treated as ever 5 minutes , hours, days, or months. Replacing the 5 with another numerical value will change this option.
2,4,6  --  treated as an OR, so if placed in the hours, this could mean at 2,4 or 6 o-clock.
9-17 treats for any value between 9 and 17. So if placed in day of month this would be days 9 through 17. Or, if put in hours it would be between 9 and 5.

Crontab commands:
crontab  –e   :  Edit your crontab file or create one if it doesn't already exist. ( It works in Linux only) .
crontab  -l     : Display your crontab file.
crontab –r     : Remove your crontab file.
crontab  -u    : If combined with –e, edit a particular user's crontab file and if combined with –l , display a particular user's crontab file. If combined with –r, deletes a particular user's crontab file.

Cron jobs example:

To check the assigned cron jobs of currently logged in user.
·         To check the cron jobs the command is
{machindra:root} crontab -l
#ident  "@(#)root       1.21    04/03/23 SMI"
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean

·         To check the cron jobs of a particular user
#crontab –l –u <user name>
#crontab –l –u machindra
·         To set the cron job with condition: script should run at each hour at 20th min on 15th date of 3rd to 7th month of each year.
# 20 * 15 3-7 * /Personal/Send_Status.sh
Posted by Machindra Dharmadhikari On 9/11/2012 01:32:00 AM 1 comment

1 comment:

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner