Monday, March 26, 2012

Scripting

Create a script to monitor a process. There are many ways to accomplish it. I like to keep it simple for maintenance reasons. I create the script and then create a cron job to run it periodically.


Step 1)Create the shell script. Include comments such as date created, brief explanation of what it does, and name of file.
#!/bin/bash
#
#2012Mar26
#
#check.process.sh
#
#This script checks if xyz process is running on localhost.
#If running, then do nothing. If not running, send
#email alert.
`if ! pgrep -f "/usr/bin/xyz"; then /bin/mail -s "Alert! XYZ Process not running!" me@email.com > /home/user/logs/cron.check.txt

Note-Don't forget to give the script executable permissions, chmod 755 check.process.sh




Step 2)Create the cron job, crontab -e
# m h dom mon dow command
#
#Check if xyz process is running-/usr/bin/xyz
15 * * * * /home/user/scripts/check.process.sh


Done.

No comments: