kyh74
asked on
writing script to check that a process is running
Hi, I am very new to Unix and i would to write a script to stop and start a daemon. I know how to do that portion but i would like the script to also check that daemon has been stop before excuting the start command. I know manually the command "ps -ef|grep daemon" can check for running daemon. May i know how can i incorporate this portion in my script.Thank you.
You may want to use the ps -e without the -f switch. I have found that in some cases if the path to the process is too long the name of the process is not displayed by the ps and the grep then fails. It caught me a couple of times.
Cheers - Gavin
Cheers - Gavin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi SEve, I have try something similar to this but "ps -ef|grep daemon" command will always return value. Even there is no such daemon running it will also return the value "grep daemon".
hi kyh74, let's change the command to :
ps -ef | grep daemon | grep -v grep
that means exclude all lines which include word grep, i.e. the process which we ran to find your daemon. this will help, seve
ps -ef | grep daemon | grep -v grep
that means exclude all lines which include word grep, i.e. the process which we ran to find your daemon. this will help, seve
ASKER
The command
"ps -ef | grep sshd | grep -v grep | awk '{print $2}"
solve the problem
thank all for the help.
"ps -ef | grep sshd | grep -v grep | awk '{print $2}"
solve the problem
thank all for the help.
#!/sur/bin/csh -f
set result = `ps -ef|grep daemon`
if ("$result" == "") then
# no such process
do your stuff
else
# process is not stopped
another stuff
endif
seve