Setting up cron to proccess a Bash Script to run every 15 minutes
I would like to set up cron to proccess a Bash Script to run every 15 minutes.
The script is listed below for your review and modification: Code Start======================================== #!/bin/bash # Simple SHELL script for Linux and UNIX systems that will monitor the # hosts with the ping command and email failed ping requests to your email address # ------------------------------------------------------------------------- # add ipaddress or hostnames that will be monitored # hostname and ipaddress are separated by a space HOSTS="192.168.1.1 24.234.0.71 10.1.0.1" # number of ping request COUNT=1 # email report when a host does not reply back SUBJECT="A host is Down!" EMAILID="admin@localhost.com" for myHost in $HOSTS do count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') if [ $count -eq 0 ]; then # 100% failed echo "Host : $myHost is down (There was no reply from this host) at $(date)" | mail -s "$SUBJECT" $EMAILID fi done Code End======================================== |
What is your question?
Does everything work? If not, what doesn't work, and exactly what does it do instead? |
The Script works fine.
I would like to stream line it so that the script reads from a text file instead of reading from this line that is coded within the script. # add ipaddress or hostnames that will be monitored # hostname and ipaddress are separated by a space HOSTS="192.168.1.1 24.234.0.71 10.1.0.1" As you can see this line within the script would be and can become very long and unmanageable and I would run the risk of causing damage to the script by having to add or remove a hosts ip address. I would like for the script to read from a text file instead of the above line. I am trying to set the script up to run every 15min. via a cron job. I placed the script in the bin folder and setup all the correct rights for the script to be runned from any term window. The results of the script is listed below for your review. ------------------------------------------------------ Subject: A host is Down! Date: Wednesday 25 July 2007 21:10 From: "Ghost" <ghost@ghost.com> To: admin@ghost.com Host : 10.1.0.10 is down (There was no reply from this host) at Wed Jul 25 *21:10:54 PDT 2007 ------------------------------------------------------ |
Quote:
Code:
for myHost in `cat hostlist` Quote:
Code:
0,15,30,45 * * * * $HOME/bin/myScript.sh |
All times are GMT -5. The time now is 06:06 PM. |