Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2503656
  • 博文数量: 540
  • 博客积分: 11289
  • 博客等级: 上将
  • 技术积分: 6160
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-11 20:27
个人简介

潜龙勿用,见龙在田

文章分类

全部博文(540)

文章存档

2018年(2)

2013年(5)

2012年(24)

2011年(104)

2010年(60)

2009年(217)

2008年(128)

分类:

2008-08-28 11:37:38

本脚本使用了函数功能。
#!/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
阅读(1228) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~