Skip to content

Instantly share code, notes, and snippets.

@razius

razius/run-once.sh

Last active Dec 26, 2015
Embed
What would you like to do?
Check if a command is running already, if not start it with the provided arguments.
#!/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
You can’t perform that action at this time.