Shell脚本如下:
#!/bin/bash
recvflag=''
recvcount=`netstat -lntp |grep 18888 | awk -F' ' '{print $2}'`
proid=`ps -ef |grep [f]pMessageSend | awk -F' ' '{print $2}'`
datetime=`date +"%Y-%m-%d %T"`
if [ $recvcount -gt 0 ]; then
recvflag=1
else
recvflag=0
fi
echo $datetime Recv-Q:$recvcount Recv-Flag:$recvflag >> /tmp/fpMessageSend.log
if [ $recvflag -eq 1 ]; then
#kill -9 $proid
sleep 1
#systemctl restart fpMessageSend_92360424L562938299_0.service
if [ $? -eq 0 ]; then
echo '200 OK' >> /tmp/fpMessageSend.log
else
echo '404 Error' >> /tmp/fpMessageSend.log
fi
fi
计划任务如下:
*/15 8-21 * * * sh /shell/restartpro.sh