登录  | 加入社区

黑狼游客您好!登录后享受更多精彩

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

查看: 649|回复: 0

shell教学:linux 守护进程脚本

[复制链接]

 成长值: 35935

8169

主题

7094

帖子

6831

现金

黑狼创办人

Rank: 12Rank: 12Rank: 12

积分
6831
发表于 2017-10-26 01:55:33 | 显示全部楼层 |阅读模式 来自 美国
用途:用于监控某应用程序的脚本。
#!/bin/sh
PROC_NAME="isearch" # 这里是你要监控的进程名
NUM=`ps aux|grep -v grep|grep $PROC_NAME|wc -l`#查询进程名,然后屏蔽掉grep, wc统计结果行数
if [ $NUM -eq 0 ];then #如果是0 证明进程不在,重启这个进程即可。
/bin/sleep 3 #休眠三秒
cd /var/yuqing_4.0/isearch/bin #程序所在目录
echo "now start isearch"
nohup ./isearch.8056 >/dev/null 2>&1 #使用nohup启动
/bin/sleep3
else
echo "the isearch is alive" #否则 提示进程存在
fi
将以上代码保存为monitor.sh
#sh monitor.sh 即可运行
这里再增加一个启动monitor的脚本。
#!/bin/sh
PROC_NAME="monitor"
NUM=`ps aux|grep -v grep|grep $PROC_NAME|wc -l`
if [ $NUM -eq 0 ];then
cd /var/yuqing_4.0/isearch
echo "now start monitor script"
nohup watch sh monitor.sh > /dev/null 2>&1#这个脚本跟上面大同小异,只是这里使用watch 监控。
/bin/sleep3
else
echo "the isearch monitor script is alive"
fi
#保存为watch_monitor.sh
sh watch_monitor.sh 即可。




上一篇:shell中截取文本
下一篇:Linux命令行与shell脚本编程大全(第三版)(六)
您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

 

QQ|申请友链|小黑屋|手机版|Hlshell Inc. ( 豫ICP备16002110号-5 )

GMT+8, 2024-5-15 05:59 , Processed in 0.054388 second(s), 44 queries .

HLShell有权修改版权声明内容,如有任何爭議,HLShell將保留最終決定權!

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表