|
[root@monitor monitor_script]# ./alert_ping.sh
: command not foundne 6:
: command not foundne 17:
'/alert_ping.sh: line 18: syntax error near unexpected token `
'/alert_ping.sh: line 18: `mail_body()
*************************[code]**********************************
# !/bin/sh
# Scriptname: Alert Ping
# Purpose: Ping all the local server for monitor
# Writed by: ^.^
# Script start ...
# Define
counter=0
hostname=`hostname`
script_path=/home/monitor_script/
log_path=$script_path/log
mail_path=$script_path/sendmail_header
music_path=$script_path/danger.au
mail_list=$script_path/maillist
ip_list=$script_path/iplist
ErrTime=`date +%Y/%m/%d/%H:%M:%S`
mail_body()
{
addressee=$1
mail_file=$2
echo "From: Monitor_Pc_NP@server" > $mail_path
echo "To: $addressee" >> $mail_path
echo "Subject: Server Ping Report from $ipaddress" >> $mail_path
echo "Content-Type: html; charset=big5;" >> $mail_path
echo "" >> $mail_path
echo "$ErrTime" >> $mail_path
echo "" >> $mail_path
echo "$hostname" "$ipaddress" "Can not be connected" >> $mail_path
echo "" >> $mail_path
echo "Monitor System run times: $counter" >> $mail_path
echo "" >> $mail_path
echo $mail_file
sendmail $addressee < $mail_path
}
sned_mail()
{
mail_list=$1
mail_file=$2
while read line
do
mail_body $line $mail_file
done
}
counter=`expr $counter + 1`
echo "Counter: $counter"
echo "Monitor begin."
cat $ip_list | grep -v '^#' | awk '{ print $1 }' | while read ipaddress
do
ping -c 1 -w 5 $ipaddress 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
send_mail $mail_list
#play -v 50 -p $music_path >/dev/null 2>&1
echo $ipaddress "Can not be connected"
echo "$ErrTime"" ""$hostname"" ""$ipaddress"" Can not be connected" >> $log_path
else
echo $ipaddress "is alive."
fi
done
echo "The end." |
|