auto_check_nginx_vip.sh
更新:HHH   时间:2023-1-7


#!/bin/bash
#auto check nginx vip
#by author andy
VIP="10.0.0.88"
IP="ifconfig | sed -n '2p'|awk -F' ' '{print $2}'"
NUM="$(ps -ef | grep nginx | grep -vcE "grep|check")"
ping -c 2 $VIP >>/dev/null
if [ $? -ne 0 ]; then
if [ $NUM -ne 0 ]; then
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth0:1
cat >ifcfg-eth0:1<<EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
NAME=eth0
IPADDR=$VIP
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=
DNS2=
EOF
ifup eth0:1
ip addr
else
ifdown eth0:1
fi
else
if [ $NUM -eq 0 ]; then
ifdown eth0:1
fi
fi

返回开发技术教程...