Shell判断子进程(pid)状态实现动态循环

来源:互联网 发布:淘宝店铺哪里买 编辑:程序博客网 时间:2024/06/15 08:12
[root@zhangwan2 xingcheng]# cat get_data_1.sh.20171101 #!/bin/bash#Date:2017/7/29#Author: create by xingcheng#Mail:#Function:抓取微信后台数据状态监控,二次判断执行脚本。##################################################################################加载环境变量source /etc/profile#设置系统语言#export LANG="en_US.UTF-8"##################################################################################定义变量DIR=/web/wechatbi/processtime1=$(date +%s)#################################################################################cd $DIRchown -R php-fpm /web/wechatbi/public/qrcodechown -R php-fpm /web/wechatbi/logs##################################################################################查看进程Semih(){sleep 180count=$(ps aux|grep 'php /web/wechatbi/tasks/cli.php thread index'|grep -v "grep" |wc -l)    if [ $count -eq 0 ]    then        get_started        Judgement_time    else        Judgement_time    fi}##################################################################################拉起子脚本get_data_2(){for I in  $(seq 1 100)do  {  /bin/bash /home/xingcheng/xingcheng/get_data_2.sh  }&  sleep 2done}##################################################################################判断次数轮训次数Judgement_time(){local time2=$(date +%s)if [ $(($time2-$time1)) -ge 9000 ]then    kill -9 $(ps aux|grep 'php /web/wechatbi/tasks/cli.php thread index'|awk '{print $2}')    exitelse    Semihfi}##################################################################################清理数据库get_started(){php /web/wechatbi/tasks/cli.php  recover recover >/web/wechatbi/logs/get_data.log 2>/web/wechatbi/logs/get_data.errget_data_2}#################################################################################get_startedSemih

二、子脚本

[root@zhangwan2 xingcheng]# cat get_data_2.sh #!/bin/bash#Date:2017/7/29#Author: create by xingcheng#Mail:#Function:抓取微信后台数据状态监控,二次判断执行脚本。source /etc/profileDIR=/web/wechatbi/processcd $DIRfrequency=1function judge(){   php /web/wechatbi/tasks/cli.php  thread index $(cat $pid_2) >/web/wechatbi/logs/get_data.log 2>/web/wechatbi/logs/get_data.err   local status_2=$(echo $?)   frequency=$(($frequency+1))   if [ $status_2 -ne 0 -a $status_2 -ne 137 ]   then       if [ $frequency -eq 5 ]       then           /usr/bin/python /home/xingcheng/monitor/mail/mail.py "99999999@qq.com"  "Error(): error in zhuashuju"  "$1"           exit       else           sleep 10           judge $(cat $pid_2)      fi  fi}php /web/wechatbi/tasks/cli.php thread index >/web/wechatbi/logs/get_data.log 2>/web/wechatbi/logs/get_data.errstatus_1=$(echo $?)pid_1=$(echo $$)pid_2=$(($pid_1+1))if [  $status_1 -ne 0 -a -f $pid_2 ]  then      judge $(cat $pid_2)fi
原创粉丝点击