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.

252CHAPTER 11Automating Tasks with ScriptsThe last two examples in this section show how to add a simple command as the crontask. Let’s go back to the example bash script you have been working on to gather systemresources. You can configure cron to execute the script using one of the previouslymentioned methods and then as part of that same cron task have the file emailed to theadministrator.For example, if you are adding the file resources to the /etc/cron.d/ directory to controlprecisely when the script runs, modify the following entry and save it in a file named/etc/cron.d/resources:47 02 * * * root /usr/local/bin/get-resources > /var/log/resources; \cat /var/log/resources | mail -s "Resources report for `echo $HOSTNAME`" \admin@example.comThe mail command is provided by the mailx package. For this command to work, thesystem must be properly configured to send email. Refer to Chapter 18, “Setting Up anEmail Server with Sendmail” for details.SummaryThis chapter provided you with an overview of some common scripting languages availablefor <strong>Red</strong> <strong>Hat</strong> <strong>Enterprise</strong> <strong>Linux</strong> to help you start writing your own scripts. Think abouttasks you perform on a regular basis and whether they can be automated with a script. Ifthey can be scripted, also consider automating their execution at set intervals using thecron utility.

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

Saved successfully!

Ooh no, something went wrong!