Comments on: linux script to check if a service is running and start it, if it’s stopped https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/ Yet another blog Tue, 25 Jun 2019 05:45:05 +0000 hourly 1 https://wordpress.org/?v=5.4.10 By: Ashutosh Joshi https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-198607 Tue, 25 Jun 2019 05:45:05 +0000 http://www.akamaras.com/?p=1541#comment-198607 In reply to makarim.

thats true …u can also check by using sh -x

]]>
By: akamaras https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-198148 Sun, 02 Jun 2019 14:57:43 +0000 http://www.akamaras.com/?p=1541#comment-198148 In reply to AJITH.

Just make it executable

chmod +x myscript.sh

And try to set it in crontab again

]]>
By: Linux Useful Commands | Linux, DevOps & AWS https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-197897 Thu, 23 May 2019 09:46:14 +0000 http://www.akamaras.com/?p=1541#comment-197897 […] http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stop… […]

]]>
By: MishaHrt https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-197852 Tue, 21 May 2019 12:27:29 +0000 http://www.akamaras.com/?p=1541#comment-197852 Hi akamaras,
I’m also a newbie. Could you help with a script that checks a service on a remote host, and starts the service on my local host if the remote host service isn’t running?

]]>
By: AJITH https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-197848 Tue, 21 May 2019 09:34:26 +0000 http://www.akamaras.com/?p=1541#comment-197848 hello

The script does not run when the cronjob is set , but runs perfectly fine when running the script manually

Thanks
AJITH

]]>
By: makarim https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-196246 Tue, 26 Mar 2019 06:41:57 +0000 http://www.akamaras.com/?p=1541#comment-196246 In reply to vibhu.

This is old thread, but the problem is value of $(ps -ef | grep -v grep | grep $service | wc -l) is different beetwen terminal and bash script.

So to fix this, please assign like this:
data=$(ps -ef | grep -v grep | grep $service | wc -l)

and then, echo $data to know the real value of those.

I found, when service start value is 5, and service off value is 2.

By using if else (value>0) the return value is always TRUE..

so you can fix with new if else with real return value from bash script not from terminal.

]]>
By: Emelyn https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-193199 Mon, 11 Feb 2019 07:01:11 +0000 http://www.akamaras.com/?p=1541#comment-193199 I have around 82 services like the below .to check the status and restart if its down.
Could you please help me with the code to check and restart without repeating the lines

ps -ef| grep -i “$path/eventProcessor EVP ACT” |grep -v grep
if [ $? -ne 0 ]
then
echo “process EVP ACT not running”
nohup $path/eventProcessor EVP ACT &

fi

ps -ef| grep -i ” /apps/lp/bin/eventProcessor EVP ALL” |grep -v grep
if [ $? -ne 0 ]
then
echo “process EVP ALL not running”
nohup /apps/lp/bin/eventProcessor EVP ALL &
fi

]]>
By: Ahamed Nawas Mohamed https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-188251 Wed, 02 Jan 2019 10:50:27 +0000 http://www.akamaras.com/?p=1541#comment-188251 i want to do get like this

1. I have 7 instances and management server
2. need to restart 1 by 1 httpd service.
3. first restart 1 instance and get the status through management server. if service up and running it’s going to next server and do the same process. like this i have to do the httpd restart.
4.

]]>
By: akamaras https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-185319 Sun, 02 Dec 2018 10:51:12 +0000 http://www.akamaras.com/?p=1541#comment-185319 In reply to Omneya.

Check out this post about sending emails from cli http://www.akamaras.com/linux/howto-send-email-from-console/

]]>
By: Omneya https://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/#comment-185035 Fri, 30 Nov 2018 15:31:15 +0000 http://www.akamaras.com/?p=1541#comment-185035 Hello everyone 🙂

i need a script to check the status of the the server and send the output to my email
and preferable to restart it if it is down.

How could i do this?

]]>