python-invert.sh 470 B

123456789101112131415
  1. #!/bin/bash
  2. # This bash script (1) runs a python script if not already running
  3. # or (2) kills the script if already running. Easily put, it inverts
  4. # the running state of the script. Great for toggling GUI scripts.
  5. # Run chmod +x python-invert.sh and then run this with the python
  6. # script path as parameter: ./python-invert.sh path/to/script.py
  7. script_name=${1}
  8. if pgrep -f "python $script_name" &>/dev/null; then
  9. pkill -f $script_name
  10. else
  11. python $script_name
  12. fi