View Full Version : bash: test if program is running
jmc1024
July 2nd, 2007, 12:54 AM
I have a cron job that runs 'xfdesktop --reload' every 10 mins. If xfdesktop is not running
then I get errors. So I want to write a bash script that tests if xfdesktop is running before
running 'xfdesktop --reload'. Is there something besides ps and awk that I can use?
Thanks,
Mark
meatpan
July 2nd, 2007, 01:41 AM
Just curious, is there a specific reason why you don't want to use ps? This is a very easy task if you use ps.
diatribe
July 2nd, 2007, 01:48 AM
Just curious, is there a specific reason why you don't want to use ps? This is a very easy task if you use ps.
indeed you are making a simple task more complicated
jyba
July 2nd, 2007, 10:15 AM
I agree with both replies above, ps is the right tool. A shorthand way of doing it would be would be...
ps -C "xfdesktop" >& /dev/null; [[ $? -eq 0 ]] && xfdesktop --reload || xfdesktop
Or, if you prefer a slightly clearer version...
ps -C "xfdesktop" >& /dev/null
if [[ $? -eq 0 ]]; then
xfdesktop --reload
else xfdesktop
fi
jmc1024
July 2nd, 2007, 11:31 PM
Thanks for the replies. ps -C is just what I needed. I didn't know it was available. Should have read
the man page...
Thanks again,
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.