Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mintplugins/216b7a2ec9d858450ad7625c05e1eea7 to your computer and use it in GitHub Desktop.
Save mintplugins/216b7a2ec9d858450ad7625c05e1eea7 to your computer and use it in GitHub Desktop.
Put this code in a shell file called "email-if-files-changed" somewhere on your server. Then link to it from a cronjob in your crontab file using this line: 01 1 * * * root /path-to-your-custom-script/email-if-files-changed
#!/bin/bash
FILES_CHANGED=$(find /var/www -type f -mmin -$((60*24)) -printf '%TY-%Tm-%Td %TT %p\n' | sort -r)
if [ !$FILES_CHANGED ]
then
curl -s --user 'api:MAILGUN_API_KEY' \
https://api.mailgun.net/v3/YOURMAILGUNDOMAIN/messages \
-F from='Name of your server<support@yourdomain.com>' \
-F to=support@yourdomain.com \
-F subject='No files were changed in the last 24 hours' \
-F text="$FILES_CHANGED"
else
curl -s --user 'api:MAILGUN_API_KEY' \
https://api.mailgun.net/v3/YOURMAILGUNDOMAIN/messages \
-F from='Name of your server<support@yourdomain.com>' \
-F to=support@yourdomain.com \
-F subject='Files were changed in the last 24 hours' \
-F text="$FILES_CHANGED"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment