Click to See Complete Forum and Search --> : bash - checking on a process
Frown
06-18-2005, 11:40 AM
I want to make a bash script and run it in cron for a week while I'm gone, it should check if azureus is running and if it is not, start it. I have this so far:
#!/bin/bash
if [ -n `ps -A | grep azureus` ]
then
nohup azureus &
else
echo "still running"
fi
Now it always thinks the process is running, but I don't know why.
DSwain
06-18-2005, 01:04 PM
Well sir it's been a while since I've done any bash scripting but now it's summer and I'm already bored (seriously it's only been hours and I'm bored.)
It's odd though, I've been messing around with a variety of combinations and getting no results. I can only manage to manipulate it to just always run the process again and again. I'll keep trying though and see if I can get any new results.
goon12
06-18-2005, 03:24 PM
This might not be the best way to do it, but try this:
ps -ef | grep -v grep | grep azureus; echo $?
That will print a 1 if it's not running, or a 0 ( zero ) if it is.
If you do it with out the "grep -v grep" , the grep it probably spitting out the line "grep azureus" so $? would be zero.
goon12
PS There is probably a more elegant solution.
Frown
06-18-2005, 04:47 PM
Your code seems to output 0 every time, even when azureus is running.
But never mind, I'll just start azureus directly every hour or so, since it terminates itself right away if another instance is already running.
bwkaz
06-18-2005, 10:21 PM
ps -C azureus >/dev/null || (nohup azureus &)
This will only work on some versions of ps, but it's extremely handy if it does work on yours. (Most Linuxes should have a ps that does accept -C.)
Frown
06-19-2005, 05:06 AM
ps -C azureus >/dev/null || (nohup azureus &)
This will only work on some versions of ps, but it's extremely handy if it does work on yours. (Most Linuxes should have a ps that does accept -C.)That works great! Thanks a lot.