Chapter 9 Study Guide: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''Scheduling commands in Linux.''' | '''Scheduling commands in Linux.''' | ||
at daemon (atd) – used to schedule a command to be executed one time in the future. | at daemon (atd) – used to schedule a command to be executed one time in the future. | ||
Line 15: | Line 14: | ||
at>date | at>date | ||
at>time | at>time | ||
CTRL-Z to end. | CTRL-Z to end. | ||
Line 80: | Line 77: | ||
# Example of job definition: | |||
# .---------------- minute (0 - 59) | # .---------------- minute (0 - 59) | ||
# | .------------- hour (0 - 23) | # | .------------- hour (0 - 23) | ||
Line 87: | Line 84: | ||
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | ||
# | | | | | | # | | | | | | ||
# * * * * * command to be executed | # * * * * * command to be executed | ||
§ The fields are separated by a space and * indicates a wild card for all time periods. | § The fields are separated by a space and * indicates a wild card for all time periods. | ||
§ If you want more than one consecutive day, you can specify the day range with a –(dash). | § If you want more than one consecutive day, you can specify the day range with a –(dash). |
Revision as of 23:03, 22 March 2012
Scheduling commands in Linux. at daemon (atd) – used to schedule a command to be executed one time in the future.
cron daemon (crond) – used to schedule a command to be executed repeatedly in the future.
AT:
The shells environment and scheduled commands are stored in the /var/spool/at directory.
Schedule a job.
at (timespec)
at>date at>time CTRL-Z to end.
Display a list of AT jobs:
at –l
Display variables for Job ID:
at –c 1
Delete a AT job:
at –d 1
To process a script:
at 12:01am July 4 –f /home/user1/Happy4th.sh
Limiting access to the at daemon:
§ Access to scheduling at jobs can be limited with the /etc/at.allow and /etc/at.deny files. ú If the files do not exist, only root can schedule tasks with the at daemon. ú To allow users, create the /etc/at.allow file and add the username, one per line. ú To deny users, create the /etc/at.deny file. Anyone not in the file is then allowed to use the at daemon. Note: if both files exist, the system only processes the /etc/at.allow file and ignores /etc/at.deny.
CRON: The table is separated into 6 fields by a space or tab. The first five field specify the times to run the command and the sixth field is the absolute path to the command to be run.
Access to scheduling at jobs can be limited with the /etc/cron.allow and /etc/cron.deny files.
§ On a newly installed Fedora system, all users have the ability to schedule tasks with cron daemon as the /etc/cron.deny contains only a single blank line.
ú To allow users, create the /etc/cron.allow file and add the username, one per line. This would then limit the system compared to a clean install to only those users.
ú To deny users, create the /etc/cron.deny file. Anyone not in the file is then allowed to use the at daemon.
Note: if both files exist, the system only processes the /etc/cron.allow file and ignores /etc/cron.deny.
To create or edit a user cron table use the –e option. The editor for crontab entries is the vi editor crontab –e Note: The crontab information is stored in the /var/spool/cron/username directory. Username is the name of the user that executed the crontab –e command.
Examples: /var/spool/cron/dave or /var/spool/cron/root
To list the contents of your user cron table use the –l option.
§ crontab –l
To remove a cron table and all the scheduled jobs you can use the –r option. § crontab –r
Note: all the previous commands are specific for the user running them. Note: root can list, edit or remove other users cron tables by using the -u option with the username.
Examples: crontab –l –u dave or crontab –r –u randy
- Example of job definition:
- .---------------- minute (0 - 59)
- | .------------- hour (0 - 23)
- | | .---------- day of month (1 - 31)
- | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
- | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
- | | | | |
- * * * * * command to be executed
§ The fields are separated by a space and * indicates a wild card for all time periods. § If you want more than one consecutive day, you can specify the day range with a –(dash). § If you want more than one time period non-consecutive you can separate them by a comma. § If you want to specify a particular time period, every 10 min, you can specify the *(every minute) /10.
§ Administrative tasks that are performed on an hourly, daily, weekly or monthly basis can be scheduled simply by placing the shell script in the following directories.
ú Scripts to be executed hourly - /etc/cron.hourly directory.
ú Scripts to be executed daily - /etc/cron.daily directory.
ú Scripts to be executed weekly - /etc/cron.weekly directory.
ú Scripts to be executed monthly - /etc/cron.monthly directory.
§ The cron daemon runs the /etc/cron.d/Øhourly script which executes the files in the directory /etc/cron.hourly one minute past the hour, every hour.
§ For troubleshooting purposes: The /etc/cron.hourly/Øanacron file starts the anacron daemon which then executes the contents of the /etc/cron.daily, /etc/cron.weekly, and the /etc/cron.monthly directories at the times specified in the /etc/anacrontab file.