该脚本的作用是可以做到监控mydns的服务,其中包括mysql和mydns
#!/bin/bash
path=/
logfile=/var/log/moniter.log
date=`(date +%D--%T)`
hostname=qubaoquan.test.com
ip=192.168.10.195
sleeptime=30
mydnsmessege="the mydns server have reboot"
mysqlmessege="the mysql server have reboot"
$path/check_dns -H $hostname -s $ip>$path/respone.txt
valuese=`(awk '{print $2}' $path/respone.txt | sed 's/://g')`
mydns=`(awk '{print $1}' $path/respone.txt)`
mysql=`(awk '{print $4}' $path/respone.txt)`
mydnsdown=CRITICAL
ok=OK
sqldown=not
if [[ $valuse != $ok ]]
  then
        if  [[ $mydns == $mydnsdown ]]
        then
  ifconfig eth1 down;killall -9 mydns;service mydns start;echo "$mydnsmessege on  $date">>$logfile;sleep $sleeptime;ifconfig eth1 up
        elif   [[ $mysql == $sqldown ]]
        then
  ifconfig eth1 down;killall -9 mysqld;service mysqld start;echo "$mysqlmessege on $date">>$logfile;sleep $sleeptime;ifconfig eth1 up
        fi
fi