Skip to content

Instantly share code, notes, and snippets.

@ms1995
Last active May 26, 2018 22:19
Show Gist options
  • Save ms1995/11a2b960c3e2934fe8d6ca67216e2069 to your computer and use it in GitHub Desktop.
Save ms1995/11a2b960c3e2934fe8d6ca67216e2069 to your computer and use it in GitHub Desktop.
Automatically re-run a process after it exits. Usage: auto-rerun.sh INTERVAL CMD [ARGS...]
#!/bin/bash
running=1
finish() {
running=0
}
trap finish SIGINT
CMD="${@:2}"
while (( running )); do
$CMD
echo "Trying to re-run $CMD in $1 second(s)..."
sleep $1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment