Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Forked from davidalger/compare_and_email.sh
Created September 28, 2016 23:18
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 molotovbliss/863d5afac8b9d68f6e0076297c1300cc to your computer and use it in GitHub Desktop.
Save molotovbliss/863d5afac8b9d68f6e0076297c1300cc to your computer and use it in GitHub Desktop.
Uses git to detect changes in web root and email administrators daily
#!/bin/env bash
#
# Example use: Add the following line to your crontab to run the script on a daily basis.
#
# 1 6 * * * ~/bin/compare_and_email.sh <full_path_to_webroot> "Email Subject Line" "user@example.com user2@example.com"
#
date=`date +%Y%m%d`
gitdir="$1"
subject="$2"
emails="$3"
cd "$gitdir"
bash -c 'echo "## changes sha1sum" $(echo $(git diff -a && git diff -a --cached) | sha1sum) "HEAD ref" $(git rev-parse HEAD) && git status -sb' > ~/daily_status/status/${date}_git_status.txt
results=`git diff ~/daily_status/yesterday.txt ~/daily_status/status/${date}_git_status.txt`
changed=$?
cp ~/daily_status/status/${date}_git_status.txt ~/daily_status/yesterday.txt
if [ $changed -ne 0 ]
then
echo -e "$results" | mail -s "$subject" "$emails"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment