gabriel
asked May 11 2017
Answer
Use service status command or else make use of below script to check is service is running or not.
Script:
Location: /home/user1/test.sh
#!/bin/sh
service=httpd
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "Service is running successfully"
else
/etc/init.d/$service start
echo "Service had stopped and now its started"
fi
Once you run this script, it will check for the httpd service. You can also place it in cron as follows.
# crontab -e
* * * * * /bin/sh /home/user1/test.sh
Edit the cron as required.
jagannatharumugam
asked May 11 2017
edited Oct 05 2018
how to check if service is running in linux
How to check if some services are running in my linux machine.