1234567891011121314151617181920 |
- #!/usr/bin/env bash
- # This bash script (1) runs a python script if not already running
- # or (2) kills the script if already running. Easily put, it inverts
- # the running state of the script. Great for toggling GUI scripts.
- # Run chmod +x python-invert.sh and then run this with the python
- # script path as parameter: ./python-invert.sh path/to/script.py
- script_name=${1}
- if [ ! -z $script_name ]; then
- if pgrep -f "python3 $script_name" &>/dev/null; then
- pkill -f $script_name
- else
- python3 $script_name
- fi
- else
- echo 'No python script filename passed'
- fi
|