本脚本使用了函数功能。
#!/bin/bash
#Author: Daihaijun. 2008-8-26
IP1=192.168.1.5
IP2=192.168.1.104
IP3=192.168.1.181
IP4=192.168.1.182
IP5=192.168.1.193
IP6=192.168.1.194
IP7=192.168.1.196
MYSQLMONLOG=/data/shell/monmysqld/mysqldmon.log
mkdir -p /data/shell/monmysqld
if [ -e $MYSQLMONLOG ];then
echo "file exist!"
else
touch $MYSQLMONLOG
fi
######Difine function#######
fun()
{
echo "------------Backup start at `date +%Y-%m-%d_%H:%M:%S`-----\
---------" >>$MYSQLMONLOG
for i in "IP1" "IP2" "IP3" "IP4" "IP5" "IP6" "IP7"
do
/usr/bin/mysqladmin -h ${!i} -uroot -p9210 ping &>/dev/null
if [ $? == 0 ];then
echo "Code:$? ${!i} myslqd is alive." >> $MYSQLMONLOG
else
echo "Code:$? ${!i} myslqd is no service" >> $MYSQLMONLOG
sendEmail -f alert@jsharer.com -u "myslqd error" \
-m "${!i} myslqd is no service" -xu alert@jsharer.com -xp 29019853 \
-t alarm@jsharer.com -s 210.51.44.184:25
fi;
done
#
IP8=192.168.1.1
/usr/bin/mysqladmin -h $IP8 -uroot -pstandalonesite ping &>/dev/null
if [ $? == 0 ];then
echo "Code:$? $IP8 myslqd is alive." >> $MYSQLMONLOG
else
echo "Code:$? $IP8 myslqd is no service" >> $MYSQLMONLOG
sendEmail -f alert@jsharer.com -u "myslqd error" \
-m "$IP8 myslqd is no service" -xu alert@jsharer.com -xp 29019853 \
-t alarm@jsharer.com -s 210.51.44.184:25
fi
IP9=192.168.1.184
/usr/bin/mysqladmin -uroot -pyuanwanga ping &>/dev/null
if [ $? == 0 ];then
echo "Code:$? $IP9 myslqd is alive." >> $MYSQLMONLOG
else
echo "Code:$? $IP9 myslqd is no service" >> $MYSQLMONLOG
sendEmail -f alert@jsharer.com -u "myslqd error" \
-m "$IP9 myslqd is no service" -xu alert@jsharer.com -xp 29019853 \
-t alarm@jsharer.com -s 210.51.44.184:25
fi
IP10=192.168.1.250
/usr/bin/mysqladmin -h $IP10 -uadmin2 -pyuanwanga ping &>/dev/null
if [ $? == 0 ];then
echo "Code:$? $IP10 myslqd is alive." >> $MYSQLMONLOG
else
echo "Code:$? $IP10 myslqd is no service" >> $MYSQLMONLOG
sendEmail -f alert@jsharer.com -u "myslqd error" \
-m "$IP10 myslqd is no service" -xu alert@jsharer.com -xp 29019853 \
-t alarm@jsharer.com -s 210.51.44.184:25
fi
#IP11=192.168.1.187
#/usr/bin/mysqladmin -h $IP11 -uadmin2 -pyuanwanga ping &>/dev/null
#if [ $? == 0 ];then
# echo "Code:$? $IP11 myslqd is alive." >> $MYSQLMONLOG
#else
# echo "Code:$? $IP11 myslqd is no service" >> $MYSQLMONLOG
# sendEmail -f alert@jsharer.com -u "myslqd error" \
#-m "$IP11 myslqd is no service" -xu alert@jsharer.com -xp 29019853 \
#-t alarm@jsharer.com -s 210.51.44.184:25
#fi
echo "------------Backup end at `date +%Y-%m-%d_%H:%M:%S`-----\
---------" >>$MYSQLMONLOG
}
for((var=1;var<4;var++))
do
fun
done
exit 0
阅读(1235) | 评论(0) | 转发(0) |