Created
July 23, 2015 15:33
-
-
Save starkers/aa1ad2ab90d8762601cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| #who gets alerted | |
| DEST=your@email.com | |
| #from address | |
| FROM="noreply@server.example.org" | |
| #directory to monitor | |
| DIR=/www | |
| #permissions of a bad dir | |
| BAD_DIR=777 | |
| #and permissions of a bad file | |
| BAD_FILE=666 | |
| TMP="$(mktemp)" | |
| find "$DIR" -type d -perm $BAD_DIR 1>$TMP 2>/dev/null | |
| #count how many bad dir's were detected | |
| COUNT="$(wc -l <$TMP)" | |
| if [ "$COUNT" -gt 0 ]; then | |
| # prepare the email content | |
| EMAIL_FILE="$(mktemp)" | |
| cat > "$EMAIL_FILE"<<EOF | |
| Hi.. this is `hostname -f`:/root/bin/bad_devs_bad.sh | |
| It seems someone has been silly and set the following bad permissions :/ | |
| Please clean this up -`hostname -f` | |
| EG: | |
| find /www -type d -perm 777 -exec chmod -c 775 {} \; | |
| find /www -type f -perm 666 -exec chmod -c 664 {} \; | |
| -------------------- | |
| EOF | |
| cat >> "$EMAIL_FILE"<<EOF | |
| ###################### | |
| # directories as $BAD_DIR # | |
| ###################### | |
| EOF | |
| cat "$TMP" >> "$EMAIL_FILE" | |
| find "$DIR" -type f -perm $BAD_FILE 1>$TMP 2>/dev/null | |
| #count how many bad dir's were detected | |
| COUNT="$(wc -l <$TMP)" | |
| if [ "$COUNT" -gt 0 ]; then | |
| cat >> "$EMAIL_FILE"<<EOF | |
| ###################### | |
| # files as $BAD_DIR # | |
| ###################### | |
| EOF | |
| cat "$TMP" >> "$EMAIL_FILE" | |
| fi | |
| mailx -S from="$FROM" -r "$FROM" -s "Bad files/dirs detected on `hostname -f`" -a "/root/bin/chmod_777.jpg" "$DEST" <"$EMAIL_FILE" | |
| rm -f "$EMAIL_FILE" | |
| fi | |
| rm -f $TMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment