使用Nagios custome bash / shell脚本在远程服务器上运行服务

时间:2016-08-10 09:33:39

标签: bash shell ssh nagios nagiosxi

如果服务未运行,我必须使用Nagios Server在远程服务器(192.168.1.105)上检查服务是否正在运行,然后我想运行此服务。

我正在使用带有NRPE的Nagios

为此,我使用下面的脚本

#!/bin/bash

if pgrep -f "index.js" >/dev/null; then
echo "index.js is Running."
exit 0
else
echo "index.js is Stopped."
exit 2
fi

借助上述脚本,我可以检查服务是否正在运行。

但我的问题是,如果服务没有运行,那我怎么能运行这项服务。

对于远程服务器上的运行服务,我只需编辑上面提到的服务,如下所述

#!/bin/bash

if pgrep -f "index.js" >/dev/null; then
echo "index.js is Running."
exit 0
else
echo "index.js is Stopped."
servicestatus=$(ssh root@192.168.1.105 nohup node /root/demo/index.js > index.log &)
echo "$servicestatus"
exit 2
fi

但这不适合我。

0 个答案:

没有答案
相关问题