Created
January 6, 2019 09:29
-
-
Save adnan360/8b223bd54a01dc7a20110808aef003b3 to your computer and use it in GitHub Desktop.
Toggles a python script running (terminates if already running, runs otherwise)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/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 pgrep -f "python $script_name" &>/dev/null; then | |
| pkill -f $script_name | |
| else | |
| python $script_name | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment