12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Scheduling Tasks with Cron 251The five asterisks should be replaced by the minute, hour, day of the month, month, andday of the week on which to execute the command.The following entry in /var/log/cron confirms the addition and the execution of the task:11May 13 15:37:01 goofy crond[1824]: (*system*) RELOAD (/etc/cron.d/testing)May 13 15:47:01 goofy crond[6977]: (root) CMD (echo “testing from cron.d” >>/tmp/testing)NOTEThe cron daemon (crond) looks for new cron tasks every minute, so a log entryconfirming the addition of a cron task will not appear until the daemon re-reads thetask lists.Finally, if you want to add a cron task as a user, execute the crontab -e command as anon-root user. This utility allows each user to have his or her own list of cron tasks. Forexample, suppose the user tfox executes crontab -e and enters the content from Listing11.12. Note that the default editor used is Vi.LISTING 11.12Example crontab -e EntrySHELL=/bin/bashMAILTO=tfox22 15 13 5 * echo “testing” >> /tmp/testingThe format for each entry is similar to the format used for the files in /etc/cron.d/except the username is not specified since each crontab file created with the crontab -ecommand is specific to a user. Because the file is specific to the user, variables such aswhat shell to use and who to email if the tasks generate output can be given values at thetop of the file as shown in Listing 11.12.After the user saves the entry, it is written to the /var/spool/cron/ file,/var/spool/cron/tfox in the example. For security reasons, the/var/spool/cron/ directoryis only readable by the root user, but non-root users can execute the crontab -ecommand at any time to review their cron tasks.This simple example creates the file /tmp/testing with a line that reads testing in thefile. It is set to execute on May 13 at 3:22 p.m. After adding and saving the entry andafter it is executed, the content from Listing 11.13 appears in the /var/log/cron log file.LISTING 11.13Log Entries after Adding a User Cron TaskMay 13 15:20:09 goofy crontab[6588]: (tfox) BEGIN EDIT (tfox)May 13 15:20:42 goofy crontab[6588]: (tfox) REPLACE (tfox)May 13 15:20:42 goofy crontab[6588]: (tfox) END EDIT (tfox)May 13 15:21:01 goofy crond[1824]: (tfox) RELOAD (cron/tfox)May 13 15:22:01 goofy crond[6631]: (tfox) CMD (echo “testing” >> /tmp/testing)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!