定时任务,不方便实现每秒执行。
脚本:curlme.sh
cd /opt/proxy_test
while :
do
while read line
do
http_code=/usr/bin/curl $line -w "%{http_code}:%{time_namelookup}:%{time_redirect}:%{time_connect}:%{time_appconnect}:%{time_pretransfer}:%{time_starttransfer}:%{time_total}\n" -m 3 -s
time=date "+%Y-%m-%d %H:%M:%S"
echo "$time ${http_code} ${line}"
done<me
sleep 1
done
执行脚本方式为:
sh proxy_curl.sh >> /opt/proxytest/t$(date +\%Y\%m\%d).log 2>&1 &
me文件内容:
http://172.20.92.43:18382/umsproxy/autoProxyPlugIn/proxyIsAlive
探测自身服务,如果不在线则重启服务:
[umsauto@CD-ZLJF-ZDHYW-DMZ-VM001 bin]$ curl http://127.0.0.1:18382/umsproxy/autoProxyPlugIn/proxyIsAlive
在线
curl 命令返回值为“在线”
[root@CD-ZLJF-ZDHYW-DMZ-VM001 umsauto]# cat curlme.sh
#!/bin/bash
#
dir=/home/umsauto/apachetomcat/bin
value=$(curl http://127.0.0.1:18382/umsproxy/autoProxyPlugIn/proxyIsAlive)
sid=$(ps -ef|grep apachetomcat|grep -v grep|awk '{print $2}')
if [ "$value" != "在线" ];then
kill -9 $sid
/bin/su - umsauto -c "$dir/startup.sh"
fi
检测服务是否有残留并清除
#!/bin/bash
/usr/local/komect/Python-3.6.2/bin/ps2 '{pid} {elapsed_time} {cmdline}' | grep -v grep | grep ssh | grep 'ControlMaster=auto' | /bin/awk '{if($2>600){print $1}}' | /usr/bin/xargs -Ipid /bin/kill -9 pid
/usr/local/komect/Python-3.6.2/bin/ps2 '{pid} {elapsed_time} {cmdline}' | grep -v grep | grep ansible | /bin/awk '{if($2>600){print $1}}' | /usr/bin/xargs -Ipid /bin/kill -9 pid
转载于:https://blog.51cto.com/13032607/2402194