Last active
December 26, 2015 12:19
-
-
Save razius/7150739 to your computer and use it in GitHub Desktop.
Check if a command is running already, if not start it with the provided arguments.
This file contains 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 | |
# Check if a command is running already, if not start it with the provided arguments. | |
# | |
# Example: | |
# This will check if thunar is already running if not it will start it with the --daemon argument. | |
# ./run-once.sh thunar --daemon | |
# | |
# I use it for my awesomewm autostart script which is available here: | |
# https://github.com/razius/awesomewm/blob/master/autostart.sh | |
PID=`pgrep -f -x "$1"` | |
if [[ -z $PID ]] | |
then | |
echo "Starting $@" | |
`$@ > /dev/null 2>&1 &` | |
else | |
echo "$1 already running with $PID." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment