unbuntu下通过是否连网来运行关闭服务
#!/bin/bash
#指定ip
IP=192.168.1.1
#指定crm所在目录
CRMDIR=/home/huchy/crm-ehr-20120522-deploy/
#指定用户的密码 www.zhishiwu.com
PASSWORD_USER=123456
#定义标志位
flagPing=0
flagStart=0
flagMysql=0
flagMemcached=0
#设置ping的超时时间,查询结果,若收到正确响应则将标志位置1
for line in `ping -c2 -w 10 $IP | grep "64 bytes from $ip"`
do
flagPing=1
done
#看crm服务是否已经启动,启动了就置标志位为1
for line in `pstree | grep "java"`
do
flagStart=1
done
#看mysql服务是否已经启动,启动了就置标志位为1
for line in `pstree | grep "mysql"`
do
flagMysql=1
done
#看memcached服务是否以memcached启动,启动了就置标志位为1
for line in `pstree | grep "memcached -d"`
do
flagMemcached=1
done www.zhishiwu.com
echo "***************************************"
echo "${flagPing}"
echo "${flagStart}"
echo "${flagMysql}"
echo "${flagMemcached}"
echo "***************************************"
#如果标志位为1就是为正常运行,0就是网络有故障
if [ $flagPing == 0 ]
then
echo "$IP failed"
if [ $flagStart == 1 ]
then
cd ${CRMDIR}
./stopofbiz.sh
fi
if [ $flagMysql == 1 ]
then
echo $PASSWORD_USER | sudo -S service mysql stop
fi
echo $PASSWORD_USER | sudo -S kill -9 `ps -ef|grep memcached|grep -v "grep"|awk '{print $2}'`
else
echo "$IP success"
if [ $flagMysql == 0 ]
then
echo $PASSWORD_USER | sudo -S service mysql start
fi
if [ $flagStart == 0 ]
then www.zhishiwu.com
cd ${CRMDIR}
./startofbiz.sh
fi
if [ $flagMemcached == 0 ]
then
echo $PASSWORD_USER | sudo -S service memcached stop
memcached -d
fi
fi
#echo $PASSWORD_USER | sudo -S service mysql start
#echo $PASSWORD_USER | sudo -S service memcached stop
#memcached -d
作者 pingshizhe