小编aba*_*ihi的帖子

在 Debian 中监控进程

我想创建一个服务来监视某个进程的存在。我写了以下shell脚本:

#!/bin/sh
while :
do
w=`ps u -A | grep -P ".+Sl.+/usr/local/MySource/endpoint" -c`
sleep 10
if [ $w -lt 2 ] 
then
echo 0 > /sys/class/leds/alix\:2/brightness
killall -9 /usr/local/MySource/endpoint
nohup /usr/local/MySource/endpoint &> /dev/null &
last_endpoint_m=`date`
echo $last_endpoint_m > /tmp/endpoint_msleep
echo $w >> /tmp/endpoint_msleep
else
echo 1 > /sys/class/leds/alix\:2/brightness
fi
sleep 10
done
Run Code Online (Sandbox Code Playgroud)

如果进程存在,脚本将关闭我机器上的 LED 并启动进程。LED 应该ON在进程运行时亮起。

然后,我通过将以下行添加到以下行来运行此脚本/etc/rc.local

nohup /usr/local/MyTools/additions/XR50_endpoint_m &> /dev/null &
Run Code Online (Sandbox Code Playgroud)

当我运行时ps,我发现XR50_endpoint_m &进程在那里。

我的机器是运行 Debian 的资源有限(嵌入式)的 ALIX 板。

问题是:
变量$w …

shell monitoring debian services

5
推荐指数
1
解决办法
366
查看次数

标签 统计

debian ×1

monitoring ×1

services ×1

shell ×1