Created
December 12, 2014 09:33
-
-
Save elmarx/3a6c9d82455151b403b9 to your computer and use it in GitHub Desktop.
shell-scripts that only executes itself if it changed since the previous run.
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/sh - | |
#=============================================================================== | |
# | |
# FILE: am-i-changed.sh | |
# | |
# USAGE: ./am-i-changed.sh | |
# | |
# DESCRIPTION: simple snippet to test if the current file has changed, thus needs to be re-run | |
# | |
# OPTIONS: --- | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: Elmar Athmer ([email protected]), | |
# ORGANIZATION: | |
# CREATED: 12.12.2014 10:08 | |
# REVISION: --- | |
#=============================================================================== | |
set -o nounset | |
set -o errexit | |
FILE=/tmp/am-i-changed-status.md5 | |
touch $FILE | |
LAST_HASH=$(cat $FILE) | |
CURRENT_HASH=$(cat $0 | md5sum | xargs) | |
if [ "${LAST_HASH}" = "${CURRENT_HASH}" ]; then | |
echo "nothing to do" | |
exit 0 | |
else | |
echo "i did change, so continue running this script" | |
echo $CURRENT_HASH > $FILE | |
fi | |
echo "Hello World!" |
Author
elmarx
commented
Dec 12, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment