bash scripting
Hi,
I am trying to write a script to turn on and off bluetooth. At the moment I have two seperate scripts to do this, but I am trying to combine them into one script. I want to check for the kbluetooth process, if this is running then I want to kill it and run rc.bluetooth stop if it isn't running i want to run rc.bluetooth start and the start kbluetooth. I have found this on the net that could check for the existence of hte kbluetooth process: Code:
if ps ax | grep -v grep | grep kbluetooth > /dev/null Stuart |
Code:
pidof kbluetooth |
Quote:
Code:
ps -C kbluetooth -o pid= Code:
pgrep kbluetooth |
This way you can get rid of grep output
Code:
ps ax | grep [k]bluetooth Ciao |
I recommend the method mentioned by iiv, but adding the -x parameter:
Code:
pgrep -x kbluetooth Code:
pkill -x kbluetooth && this_runs_if_it_was_found |
All times are GMT -5. The time now is 11:23 PM. |