1830241 Members
1411 Online
109999 Solutions
New Discussion

Re: script linux

 
STL
Occasional Advisor

script linux

How i check if my process is running with a script?
ps -ef|grep pippo
how i check if pippo is running and then if not running start them??
3 REPLIES 3
Derek Whigham_1
Trusted Contributor

Re: script linux

while [ $?!=0 ]
do
ps -ef | grep bash
if [ $? -eq 0 ]
then
echo "Process Running"
else
echo "Run Your Process Here"
fi
sleep 5
done
Divide and Conquer
Ralph Grothe
Honored Contributor

Re: script linux

Just a wierd skeleton for a poor man's "monitor" of a daemon.

e.g. see if sshd is running


# while $(pkill -0 -P 1 -x sshd); do echo sshd running;sleep 5;done;echo sshd died
sshd running
sshd running
sshd running
sshd running
sshd died


When from another terminal I sut down the sshd


# service sshd stop
Stopping sshd: [ OK ]


Madness, thy name is system administration
Muthukumar_5
Honored Contributor

Re: script linux

Just like as,

#!/bin/bash
ps -ef | grep -q 'pippo'

if [[ ${?} -eq 0 ]]
then
echo "Process pippo is running!"
ps -ef | grep pippo
else
# Process Startup
/pippo &
fi

# END
exit 0
########################

hth.

Easy to suggest when don't know about the problem!