Skip to content

Instantly share code, notes, and snippets.

@jens
Last active December 29, 2015 15:09
Show Gist options
  • Save jens/7688912 to your computer and use it in GitHub Desktop.
Save jens/7688912 to your computer and use it in GitHub Desktop.
leader
#!/bin/bash
if [ "$#" -ne 2 ]
then
echo "Usage: leader portnumber command"
exit 1
fi
first_run=1
while :
do
if [[ `lsof -i :$1` ]]
then
if [[ $first_run == 1 ]]
then
echo 'port already in use. I assume it is already running...'
first_run=0
fi
else
shift
echo $@
exec "$@"
fi
sleep 1
done
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment