Skip to main content
Question

Script to see if Firefox is running

  • November 6, 2014
  • 5 replies
  • 34 views

Forum|alt.badge.img+9

I'm having trouble with a script to see if Firefox is running. I am by no means a coder, so any help is appreciated.

Here is what I am trying -

#!/bin/bash

process="Firefox"
processrunning=$( ps axc | grep "${process}" )

if [ "$processrunning" != "" ] ; then echo "$process IS running, we do nothing now"

else echo $process IS NOT running - run custom trigger here to update"

fi

exit 0

5 replies

Forum|alt.badge.img+17
  • Valued Contributor
  • November 6, 2014

The application name shown in the GUI usually matches the process or executable name, but nothing in OS X requires this. Firefox is one of the exceptions in this regard. The executable name on current versions is "firefox" and was "firefox-bin" on earlier ones. You could add the -i switch to the grep statement to ignore case or change the ps arguments to axww, which will retrieve the full path of the app, including the GUI name. The latter technique does not require you to know the executable name, but increases the risk of false positives, including from the grep process itself.


Forum|alt.badge.img+17
  • Valued Contributor
  • November 6, 2014

One other tidbit: In my experience, Firefox will actually tolerate being overwritten while running, so I don't bother checking before updating it.


Forum|alt.badge.img+5
  • New Contributor
  • November 6, 2014

You can use:

#!/bin/sh
process="Firefox"
processrunning=$(pgrep -i $process)

if [ $processrunning != "" ] 
then
     echo $process " is running. Run policy with notification to user that Firefox will be shut down."
     jamf policy -id #####
else
     echo $process " is NOT running. Run policy without notification.
     jamf policy -id #####
fi
exit 0

Forum|alt.badge.img+5
  • New Contributor
  • November 6, 2014

What we actually do where I am at (Casper 9.31 currently) is use the User Interaction Start Message to let them know an update is going to be applied and that {application} needs to be shut down. A one line script:

#!/bin/sh
killall {application}

:: set to before. The package runs, and then a User Interaction Completed Message comes up letting them know it's now safe to use {application}. We do this for a number of applications we use.

PS - I think we tried the "Files and Processes" option but I believe it killed AFTER the package ran, which doesn't work for some of the applications we use.


Forum|alt.badge.img+9
  • Author
  • Contributor
  • November 10, 2014

Working great now! Thank you all for the help!