“进程监控脚本并避免重复执行脚本”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
第2行: 第2行:
 
==mysql进程监控脚本shell==
 
==mysql进程监控脚本shell==
 
<pre>
 
<pre>
 +
cndw version
 +
 +
CPID=$$  #$$ 是脚本运行的当前进程ID号
 +
RUN="`ps -ef | grep "$0" | grep -v "grep" | grep -v "$CPID" | wc -l`"  #$0 是脚本本身>的名字
 +
[ "$RUN" -gt 1 ] && exit
 +
 +
 +
 +
 +
 +
 +
 +
 
#!/bin/bash
 
#!/bin/bash
 
# 请放到crontab中运行,如(注意要以后台方式运行,因为脚本是常驻不退出的):
 
# 请放到crontab中运行,如(注意要以后台方式运行,因为脚本是常驻不退出的):

2021年11月26日 (五) 09:19的版本

mysql进程监控脚本shell

cndw version 

CPID=$$   #$$ 是脚本运行的当前进程ID号
RUN="`ps -ef | grep "$0" | grep -v "grep" | grep -v "$CPID" | wc -l`"  #$0 是脚本本身>的名字
[ "$RUN" -gt 1 ] && exit








#!/bin/bash
# 请放到crontab中运行,如(注意要以后台方式运行,因为脚本是常驻不退出的):
# Usage */20 * * * *   /home/mon/proce-moin.sh   > /dev/null 2>&1 &

LOCK_FILE="/tmp/my.lock"
if [[ -e $LOCK_FILE ]] ; then
echo "re-entry, exiting"
exit 1
fi

### Placing lock file
touch $LOCK_FILE
echo -n "Started..."


 #ps -ef | grep  proce-moin
#if [ $? -eq 0 ]
#then 
#	exit 0
#fi
#checkmyself 
#mypn=`ps -ef | grep proce-moin | grep -v grep | wc -l`
##if  [ $mypn -gt 1 ]
#if  [ -n "$myupn" ]
#then 
#    exit 0
#fi
#


 ps -ef | grep mysqld | grep -v grep
 if  [ $? -eq 0 ]
 then 
	 echo  "mysqlok"
        #exit 1
 else
	 systemctl  start  mysqld.service

 fi
 sleep  500
### Removing lock
rm -f $LOCK_FILE

echo "Done."

R

https://github.com/eyjian/mooon/tree/master/mooon

通用的进程监控重拉起bash脚本process_monitor.sh

shell脚本监控进程


Shell脚本监控程序运行情况(重启程序)

实现简单的监控脚本(Bash的执行和异常捕获)