Created
April 13, 2023 07:08
-
-
Save andyg2/ebc0e8c4a3f991fcf1a09caf2e8fad24 to your computer and use it in GitHub Desktop.
Email if changes detected in directory
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/bash | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <directory>" | |
exit 1 | |
fi | |
directory="$1" | |
if [ ! -d "$directory" ]; then | |
echo "Error: directory does not exist: $directory" | |
exit 1 | |
fi | |
cd "$directory" | |
# Find untracked files | |
untracked=$(git ls-files --others --exclude-standard) | |
# Find unstaged changes | |
unstaged=$(git diff-files --name-only) | |
# Find uncommitted changes | |
uncommitted=$(git diff-index --quiet HEAD -- || git diff-index --name-only HEAD --) | |
# Check if any changes were found | |
if [ -n "$untracked" ] || [ -n "$unstaged" ] || [ -n "$uncommitted" ]; then | |
# Send email notification | |
echo "Changes detected in $(git rev-parse --show-toplevel)" | |
mail -s "Directory changes detected" your@email.com | |
fi | |
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
0 0 * * * /path/to/check_git_changes.sh /path/to/wp-content/themes |
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
# cd /path/to/wp-content/themes && git init && git add . && git commit -m "Initial monitor commit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment