Service checking through shell script

I want to check the postgres service for client PC which is remotely placed through shell script , whether the Postgres service is working or not.I don't have an idea to develop this script.Please give me a code.

Client PC IP Address:

10.66.1.133

You could use nc to test postgress is listening on it's port:

 if nc -w 3 -z 10.66.1.133 5432 < /dev/null > /dev/null 2>&1
then
   echo "Postgress is running"
else
   echo "Postgress NOT running"
fi

or if your using bash shell you could do:

if 2>/dev/null >/dev/tcp/10.66.1.133/5432
then
   echo "Postgress is running"
else
   echo "Postgress NOT running"
fi
1 Like

Excellent, It Superbly works ,
Please explain the above steps in ifcondition.