shell脚本判断进程是否存在,并重新启动

来源:互联网 发布:淘宝助理一键导出 编辑:程序博客网 时间:2024/05/16 10:59
shell脚本判断进程是否存在,并重新启动
[plain] view plaincopy
  1. #!/bin/bash  
  2. #  
  3.   
  4. #调用关闭jboss进程脚本  
  5. stopMethodServer.sh  
  6.   
  7. #打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v "grep" 去掉grep进程  
  8. jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"`  
  9. echo $jmsThread  
  10.   
  11. #查询jboss进程个数:wc -l 返回行数  
  12. count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l`  
  13. echo $count  
  14.   
  15. sec=7  
  16. #开始一个循环,以判断进程是否关闭  
  17.   
  18. for var in 1 2  
  19. do  
  20.   if [ $count -gt 0 ]; then  
  21.     #若进程还未关闭,则脚本sleep几秒  
  22.     echo sleep $sec second the $var time, the JMS thread is still alive  
  23.     sleep $sec  
  24.   else  
  25.     #若进程已经关闭,则跳出循环  
  26.     echo "break"  
  27.     break  
  28.   fi  
  29. done  
  30.   
  31. #if [ $count -eq 0 ]; then  
  32. # echo "nohup startMethodServer.sh &"  
  33. # nohup startMethodServer.sh &  
  34. #else  
  35. # echo "It's better to check the thread!!!"  
  36. #fi  
  37.   
  38. #调用启动脚本  
  39. nohup startMethodServer.sh &  
原创粉丝点击