req: Bash Script check if process command is running if not run it >>
I am looking for a bash script to look for a command if is running in the process tree, if not to run it.
I found lot of scripts over the net but all of them are for service/deamon, which is not working for me. This is the command that I am running in a background: ssh -f -N -L 8885:127.0.0.1:8887 some@host -p 22 for example in process tree: user 7611 0.0 0.0 5048 628 ? S<s 12:18 0:00 ssh -f -N -L 8885:127.0.0.1:8887 some@host -p 22 Any help will be appreciated! Thanks. |
Quote:
Code:
if ! ps aux|grep '...'; then ...; fi |
With 'pgrep' you can match whatever part of the process string you want (no need for ugly "ps|grep" kludges):
Code:
pgrep -f ':127.0.0.1:8887 some@host' Code:
pgrep -f 'ssh -f -N -L 8885:127.0.0.1:8887 some@host -p 22' >/dev/null 2>&1 ||\ |
Thank you very much. Have a nice day :)
|
All times are GMT -5. The time now is 08:58 AM. |