Crontab Commands

Crontab commands

To View the jobs scheduled in Cron:

crontab –l

To edit the Crontab:

crontab –e

To remove the crontab:

crontab –r

To enable the new crontab file:

  1. Create a file with all the jobs.

Let file name be: Jobstxt.lis

  1. Enable new crontab

crontab Jobstxt.lis

Crontab Entries:

A crontab file consists of lines of six fields each. The fields are separated by spaces or tabs.The first five are integer patterns that specify the following:

minute (0-59) or * (all)

hour (0-23) or * (all)

day of the month (1-31) or * (all)

month of the year (1-12) or * (all)

day of the week (0-6 with 0=Sunday) or * (all)

Ex:

15 00 * * 1-5 ksh /prod830/bat/endofday.sh >/prod830/data/log/endofday.log 2>/prod830/data/log/endofday.err

The above will run at 00:15 every month,every year, from Monday to Friday. The filename is endofday.sh and writes log to endofday.log, if errorsout it writes into error file endofday.err

Example:

min

hour

day/month

month

day/week

Execution time

30

0

1

1,6,12

*

-- 00:30 Hrs on 1st of Jan, June & Dec.

0

20

*

10

1-5

--8.00 PM every weekday (Mon-Fri) only in Oct.

0

0

1,10,15

*

*

-- midnight on 1st ,10th & 15th of month

5,10

0

10

*

1

-- At 12.05,12.10 every Monday & on 10th of every month

Check this out:

0 0 1,15 * 1 ksh /prod830/bat/endofday.sh >/prod830/data/log/endofday.log 2>/prod830/data/log/endofday.err

Please note the above cron entry. The behaviour of above one:

would run command on the first and fifteenth days of each month, as well as every Monday.

Controls on Using the crontab Command

The /var/adm/cron/cron.allow and /var/adm/cron/cron.deny files control which users can use the crontab command. A root user can create, edit, or delete these files.

The following is an example of an cron.allow file:

root

nick

dee

sarah

If the cron.allow file exists, only users whose login names appear in it can use the crontab command. The root user's log name must appear in the cron.allow file

if the file exists. A system administrator can explicitly stop a user from using the crontab command by listing the user's login name in the cron.deny file. If

only the cron.deny file exists, any user whose name does not appear in the file can use the crontab command.

A user cannot use the crontab command if one of the following is true:

* The cron.allow file and the cron.deny file do not exist (allows root user only).

* The cron.allow file exists but the user's login name is not listed in it.

* The cron.deny file exists and the user's login name is listed in it.


Thanks and Regards

D.Sasi Kumar

 

0 comments: