Ensurepass

16. Cron & At
16.1 Overview
1. Cron & at provides a way to schedule tasks.
2. Packages
o vixie-cron – Provides crond daemon and crontab editing utilities.
o crontabs – Provides default root crontab files.
o at – Provides atd daemon and command line utilities.
16.2 Crontab Files
User or system defined files that contain a command to execute and the time to execute it. Crond wakes every minute to see if any crontab files have changed and re-reads them if they have.
1. User crontabs
o Stored as /var/spool/cron/
o View with: crontab -l
o Edit with: crontab -e
o Edit a specific users crontab(root only): crontab -u
2. System crontabs
o /etc/crontab
Crontab file that configures when scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly are executed.
o /etc/cron.d
This directory contains actual crontab files that are configured just like user crontab files.
o /etc/cron.hourly
Scripts in this directory are executed on the first minute of every new hour.
o /etc/cron.daily
Scripts in this directory are executed at 4:02 AM every day.
o /etc/cron.weekly
Scripts in this directory are executed at 4:22 AM every Sunday.
o /etc/cron.monthly
Scripts in this directory are executed at 4:42 AM on the first day of the month.
3. Crontab Format
4.
Valid values:
Minute – 0-59
Hour – 0-23
Day of Month – 1-31
Month – 1-12 *or*
– Jan, Feb, Apr, etc.
Day of Week – 0-7 (0 or 7 = Sunday) *or*
– Sun, Mon, Tue, Wed, Thu, Fri, Sat
Can specify comma separate lists and ranges for each parameter but only in a numeric format (e.g. 1-5 is ok for day of week, but not Mon-Fri).
# To execute foo every 5 minutes.
0,5,10,15,20,25,30,35,40,45,50,55 * * * * foo
# – OR –
*/5 * * * * foo
# Executes bar during the bottom of every hour
# during working hours on week days.
30 8-5 * * 1-5 bar
16.3 At Jobs
1. “at” jobs are configured from the command prompt. No crontab style files.
2. At uses the existing environment that the “at” command was executed in to run the specified command(s) at the indicated time. This typically makes at jobs easier/quicker to setup than crontab jobs because the environment is already configured for the job.
3. Examples
4. at 8:00 am March 12 # Execute specified commands at 8:00 am on March 12th
5. at now +3 hours # Execute specified commands 3 hours from now
6. at 9:30 pm -f ~/cmds # Execute commands in the ~/cmds file at 9:30 pm
After specifying a time, the user is prompted for the commands to execute unless the “-f” option is used to specify a file containing the commands to execute.
7. Managing At Jobs
o atq – List pending jobs for a user.
o atrm – Delete pending jobs.
o atrm 1 # Remove job number 1 from pending queue
o
o batch – Execute specified command when system load levels are low enough to permit it.
16.4 Access Control
1. /etc/cron.allow
If it exists, a user must be listed in this file in order to use crontab.
2. /etc/cron.deny
If it exists, a user must not be listed in this file in order to user crontab.
3. /etc/at.allow
Same as cron.allow, only for “at”.
4. /etc/at.deny
Same as cron.deny, only for “at”.

Download the Ensurepass Latest 2013 RHCE EX300 Practise Test PDF to pass RHCE EX300 exam.

Comments are closed.