Joe I am writing a bash script that launches a service (in my case nagios). I want to start my script by running /etc/init.d/nagios start only if nagios is not running. I start my script with /etc/init.d/nagios stop /etc/init.d/nagios start ... I'm not sure it is the best way to go, I'd rather use an if statement. Any ideas ?
duckster try something like: #!/bin/sh if ps -e | grep nagios | grep -v grep then echo "cool, running" else /etc/init.d/nagios start (replace nagios with whatever the process name is)
Joe It worked thanks ^^ so basically in bash: if command tests if this command has an output ? Also, if the test passes, and it echoes "cool, running" it also prints the output of the method. I'm lost :-/
nuclearcat Use pidof hint home ~ # pidof bash;echo $? 19187 15787 15785 15783 15782 15546 15544 15542 15527 15526 15523 1705 1697 0 home ~ # pidof bashx;echo $? 1