1

I have to check service is running or not on Remote Server(192.168.1.105) using Nagios Server if service is not running then I want to run this service.

I am using Nagios with NRPE.

For this I am using below script

#!/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

With help of above script i am able to check service is running or not.

But my question is that if service is not running so how can i run this service.

For run service on remote server i am just edit the above service as mentioned in below

#!/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 [email protected] nohup node /root/demo/index.js > index.log &)
echo "$servicestatus"
exit 2
fi

But this is not working for me.

user3441151
  • 1,880
  • 6
  • 35
  • 79

0 Answers0