|
|
#1 |
|
MVP
Join Date: Dec 2001
Location: Portland, OR
Posts: 1,472
|
Auto restart a crashing app?
I'm running a Evological at home for a bit; it's a webcam app. It runs fine 99% of the time, but then every so often, it barfs for some unknown reason and unexpectedly quits. Re-lauching it from the Finder works fine; no prefs or anything else needs to be dealt with.
What I'd like is a way to be able to do is restart Evological via a cronned (is that a word?) shell script. I think this is relatively straightforward, except ... OS X throws up one of those "Evological has unexpectedly quit; would you like to send an error report" dialog boxes when it dies. So my questions are: (a) is there a prefs setting, third party app, anything, I can use to avoid/reply/remove that crash splash message? (b) what exactly would my script look like? I know what it is in theory, but I'm having trouble with reality .The theory version of the shell script is: Code:
ps ax | grep Evological if (Evological not found) then open /Applications/Evological.app/etc... endif thx; -rob. |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
You could use the "-q" option to grep to make it quiet (not deliver any output) and then check the result by testing the Bourne shell variable $?
which would be 0 if there were any matches in the grep, and 1 if there were no matches. I'm assuming you are using the Bourne shell (or Bash) - you shouldn't be using the C-shell for scripts. One awkward thing is that the invocation of the script itself will show up in the grep, so you need to use a well-known trick to sidestep that - put the first character of the name that you are searching for inside square brackets: [E]vological Here's a sample script that shows the idea: Code:
#!/bin/sh
# Script that checks if a specified app is running.
# You need to invoke this script with the name of the app
# but with the first letter inside square brackets
# E.g. app_running [S]afari
# (The square brackets prevent the invocation of this script
# matching in the grep of the ps results)
# Note that case does matter: [s]afari is different from [S]afari
appName=$1
echo "Checking to see if $appName is running"
ps ax | grep -q $appName
if [ $? = 0 ]; then
echo "$appName is running"
else
echo "$appName is not running"
fi
It would probably be better to use 'ps axww' to be sure that you catch the process name - some command-lines will be so long that they won't appear in full in the default 80-column width from 'ps ax' And note that since the use of this script is slightly tricky (the need to enclose the first character of the name inside square brackets), you might want to use the method shown in the script by Rob Griffiths below, even though it is slightly less efficient (it uses an extra process for the 'grep -v') [/edit] And as for getting rid of the dialog box from CrashReporter, maybe this hint will help: http://www.macosxhints.com/article.p...31206044700414 Of course that disables CrashReporter for all apps, not just Evological. Last edited by hayne; 01-29-2005 at 07:35 PM. |
|
|
|
|
|
#3 |
|
MVP
Join Date: Dec 2001
Location: Portland, OR
Posts: 1,472
|
Follow-up -- I finally got around to working on this last night, and it works much as you described. I tweaked the code as I only need to test for one app, which greatly simplifies things:
Code:
#!/bin/sh ps ax | grep Evocam | grep -v grep if [ $? = 0 ] ; then #it's up, so do nothing else #not up, so relaunch it open -a Evocam fi Thanks! -rob. |
|
|
|
![]() |
|
|