每秒一次巡查自我web页面

博客介绍了定时任务实现每秒执行的脚本,通过 curl 命令探测自身服务,若不在线则重启服务。还给出了检测服务残留并清除的脚本,使用 awk 筛选符合条件的进程并杀死,保障服务正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

定时任务,不方便实现每秒执行。

脚本: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值