Skip to content

Instantly share code, notes, and snippets.

@andyg2
Created April 13, 2023 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyg2/ebc0e8c4a3f991fcf1a09caf2e8fad24 to your computer and use it in GitHub Desktop.
Save andyg2/ebc0e8c4a3f991fcf1a09caf2e8fad24 to your computer and use it in GitHub Desktop.
Email if changes detected in directory
#!/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
0 0 * * * /path/to/check_git_changes.sh /path/to/wp-content/themes
# 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