shell實戰之:用shell實現squid守護進程
01
用shell實現squid守護進程
02
每兩分鐘檢測一下squid服務狀態,如果squid服務不在了,則啟動,達到守護的目的
03
腳本如下:
04
#!/bin/sh
05
#code by scpman
06
#mail:
[email protected]
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"