Created
March 10, 2021 18:37
-
-
Save ndgnuh/59e1e35f79ec56307c5ff32ea7677b67 to your computer and use it in GitHub Desktop.
Run once shell script
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/sh | |
| BASEDIR="/var/run/user/$(id -u)/runonce" | |
| COMMAND="$@" | |
| HASH="$(echo "$COMMAND" | md5sum | cut -d ' ' -f 1)" | |
| PIDFILE="$BASEDIR/$HASH" | |
| show_help () { | |
| echo "runonce <command>" | |
| } | |
| if [ -z $1 ]; then | |
| show_help | |
| exit | |
| fi | |
| mkdir -p $BASEDIR | |
| if ! [ -f $PIDFILE ]; then | |
| $COMMAND & | |
| echo $! > $PIDFILE | |
| wait | |
| rm $PIDFILE | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment