用于过程监控的Shell脚本 [英] Shell Script For Process Monitoring

查看:83
本文介绍了用于过程监控的Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/bin/bash
if [ `ps -ef | grep "91.34.124.35" | grep -v grep | wc -l` -eq 0 ]; then sh home/asfd.sh; fi

还是这个?

ps -ef | grep "91\.34\.124\.35" | grep -v grep > /dev/null
if [  "$?" -ne "0" ]
then
sh home/asfd.sh
else
echo "Process is running fine"
fi

你好,我该如何写一个运行过程中的shell脚本,如果没有进程名 CONTAINING 91.34.124.35,然后在某个位置执行文件,我想我以连续循环每30秒运行一次,我认为有一个睡眠命令.

Hello, how can I write a shell script that looks in running processes and if there isn't a process name CONTAINING 91.34.124.35 then execute a file in a certain place and I want to make this run every 30 seconds in a continuous loop, I think there was a sleep command.

推荐答案

您不能使用cron,因为在实现中,我知道最小的单位是一分钟.您可以使用sleep,但是您的进程将始终处于运行状态(使用cron它将每次启动).

you can't use cron since on the implementation I know the smallest unit is one minute. You can use sleep but then your process will always be running (with cron it will started every time).

只使用睡眠

while true ; do
  if ! pgrep -f '91\.34\.124\.35' > /dev/null ; then
    sh /home/asfd.sh
  fi
  sleep 30
done

如果您的pgrep具有选项-q来抑制输出(如在BSD上一样),您也可以使用pgrep -q而不将输出重定向到/dev/null

If your pgrep has the option -q to suppress output (as on BSD) you can also use pgrep -q without redirecting the output to /dev/null

这篇关于用于过程监控的Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆