python-invert.sh-e 565 B

1234567891011121314151617181920
  1. #!/usr/bin/env 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 [ ! -z $script_name ]; then
  9. if pgrep -f "python3 $script_name" &>/dev/null; then
  10. pkill -f $script_name
  11. else
  12. python3 $script_name
  13. fi
  14. else
  15. echo 'No python script filename passed'
  16. fi