Monitor Remote Service

The script below checks if a certain service of a remote server is running or not.

NOTE: For you to be able to run the script without it asking for password, you need to follow the steps from this tutorial: Passwordless SSH

#!/bin/bash
##############################
### MONITOR REMOTE SERVICE ###
##############################

##DECLARE VARIABLES
SRV="IP ADDRESS OF REMOTE SERVER"
SVC="NAME OF REMOTE SERVICE TO MONITOR"

#CHECK STATUS OF REMOTE SERVICE
RMTSVC=$(ssh root@$SRC '$SVC status' 2>&1)
if [[ "$RMTSVC" == *"is running"* ]]
then
   echo "Service is running."
else
   echo "Service is NOT running."
fi