shell实战之:用shell实现squid守护进程


shell实战之:用shell实现squid守护进程
 
01
用shell实现squid守护进程
02
每两分钟检测一下squid服务状态,如果squid服务不在了,则启动,达到守护的目的
03
脚本如下:
04
#!/bin/sh
05
#code by scpman
06
#mail:scpman@Live.com
07
#Blog:http://www.scpman.com
08
msgip="10.0.1.111"
09
IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `
10
check_squid()
11
{
12
rs_flag=`ps uaxww | grep squid|grep -v grep | wc -l`
13
if [ "$rs_flag" -gt 0 ]
14
then
15
        echo 'squid server is running..'
16
        exit;
17
else
18
        echo 'squid server is not running...'
19
        /usr/local/squid/sbin/squid -z
20
        /usr/local/squid/sbin/squid -D
21
        /usr/bin/logger -p local1.info -h $msgip "the services: $IP squid will to start by watch_squid.sh "
22
        sleep 1
23
        check_squid
24
fi
25
}
26
check_squid
27
每两分钟用定时实现,如果要1分钟检查一次,就是* * * * *了
28
定时如下
29
*/2 * * * * su - root -c "/usr/home/admin/mgr_shell/watch_squid.sh"
 

相关内容

    暂无相关文章