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 root@192.168.1.105 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
  • You are redirecting stdout to `index.log` so nothing will be in the variable `servicestatus` – 123 Aug 10 '16 at 10:11
  • @123 $(ssh root@192.168.1.105 nohup node /root/demo/index.js > index.log &) command not generating any pid of index.js – user3441151 Aug 10 '16 at 10:24
  • You are running it on a different server no? Why would you expect the process to show up on the current server? – 123 Aug 10 '16 at 10:26
  • @123 yes I have to run "nohup node /root/demo/index.js > index.log &" command on 192.168.1.105 server from 192.168.1.103 server. – user3441151 Aug 10 '16 at 10:30

0 Answers0