2/7/09

Scheduling Linux Tasks

automation and scheduling:

The at command enables the simplest form of job scheduling. It runs a command or a series of commands once only at a specified time, and mails any output to the user. The jobs it runs are processed in the background. You use this syntax for the at command. In the syntax, you can specify the time in a number of different ways. For example, you can specify the time as 01:30 or as 1:30 am.

[root@host11 pwstaff]# at -m 01:30


You now want to schedule a series of commands that you’ve saved in a file named “system_maintenance” to run at 12:00 pm. To do this, you use the -f option to Specify the file in an at command.

[root@host11 pwstaff]# at -f system_maintenance 12:00

Suppose that it is the end of June and you want to schedule a job to run four weeks from today, without entering the exact date on which it must run. Which command do you enter before specifying the job that must run to do this?

at now + 4 weeks

Ordinary users use the crontab command to create or edit their crontab files. To use the crontab command, users must be listed in the file /etc/cron.allow. If that file doesn’t exist, the users must not be listed in /etc/cron.deny. If neither file exists, all users can use the crontab command unless some other configuration prevents this.

[root@samwise root]# crontab -l

no crontab for root

[root@samwise root]# crontab -e to create

An entry of 00 in the minute field, 20 in the hour field, and 1-5 in the day of week field specifies that a command must run at 8:00 pm every day, from Monday to Friday.

00 20 * * 1-5 sort/usr/sales


In order, the fields that make up the time pattern in a crontab file entry include minute, hour, day of month, month of year, and day of week. Examples:


0 22 * * 1-5 10:00 pm on weekdays
15 14 1 * * 2:15 pm on the first of every month
30 /2 * * * Half past the hour every two hours
30 19 * * 1 7:30 pm every Monday


The /etc/at.allow and /etc/at.deny files enable you to control which users can run the at command. When a user tries to run an at job, the at command checks to see if the /etc/at.allow file exists. If it does and the user is listed in the file, at schedules the job.


If the user is not listed in /etc/at.allow, they will not be able to schedule the job, irrespective of whether they are listed in the /etc/at.deny file.If the /etc/at.allow file does not exist, at checks the /etc/at.deny file. If the user’s name does not appear in this file, the job will be scheduled. If the /etc/at.allow file doesn’t exist and /etc/at.deny is empty, any user can run at jobs. Alternatively, if /etc/at.allow exists and is empty, or if neither file exists, no user except root can run at jobs.

In some Linux distributions, such as Red Hat 7, any user can run cron jobs if neither the /etc/cron.allow or /etc/cron.deny files exist. In other distributions, only root can run cron jobs if neither file exists.

No comments:

Post a Comment