Julian Matz
asked on
Bash: check if process is running
Hi!
I'm trying to make a bash script to check if Firefox is running. If not, then I would like to start it.
So far, I have the following:
APP1="firefox"
APPCHK=$(ps aux | grep -c $APP1)
But I'm not sure about the return codes. I'd be grateful if someone could help.
The command /usb/bin/firefox will start Fx the way I want, but I think I also need to export the DISPLAY variable before hand. How do I do that in bash? This is how I'd do it from the command line:
$ export DISPALY=:0
Also, do I need to exit the bash script once Firefox is running, because normally, if I start Fx from command line I need do use something like following so that I can close my terminal session without shutting down Fx again:
$ ssh user@localhost -f -X firefox
I'm trying to make a bash script to check if Firefox is running. If not, then I would like to start it.
So far, I have the following:
APP1="firefox"
APPCHK=$(ps aux | grep -c $APP1)
But I'm not sure about the return codes. I'd be grateful if someone could help.
The command /usb/bin/firefox will start Fx the way I want, but I think I also need to export the DISPLAY variable before hand. How do I do that in bash? This is how I'd do it from the command line:
$ export DISPALY=:0
Also, do I need to exit the bash script once Firefox is running, because normally, if I start Fx from command line I need do use something like following so that I can close my terminal session without shutting down Fx again:
$ ssh user@localhost -f -X firefox
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you show me the pgrep alternative?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is a lot shorter! lol
Thanks!
Thanks!
ASKER
The ampersand in /usr/bin/firefox & is to return control to the terminal if the bash script is run from the command line.
Open in new window