@@ -16,7 +16,8 @@ if [[ -z "${SPACE_CHECK_DRIVES}" \
1616 || -z " ${SPACE_EMAIL_RECIPIENTS} " \
1717 || -z " ${SPACE_DRIVE_LIMITS} " \
1818 || -z " ${SPACE_LOG} " \
19- || -z " ${SPACE_ROOT_NAME} " ]] ; then
19+ || -z " ${SPACE_ROOT_NAME} " \
20+ || -z " ${SPACE_EMAIL_ON_PASS} " ]] ; then
2021 echo " Error: Missing one or more variables required for check_disk_space.sh"
2122 exit 1
2223fi
@@ -36,7 +37,7 @@ echo "SPACE CHECK: $(date)" >> "$SPACE_LOG"
3637EMAIL_TEMPLATE=$( cat << -EOF
3738From: "Spyglass" <$SPACE_EMAIL_SRC >
3839To: %s
39- Subject: Drive almost full: %s
40+ Subject: %s
4041
4142%s
4243EOF
@@ -48,7 +49,7 @@ send_email_message() {
4849 local SUBJECT=" $2 "
4950 local BODY=" $3 "
5051 EMAIL=$( printf " $EMAIL_TEMPLATE " " $RECIPIENT " " $SUBJECT " " $BODY " )
51- curl -s --url " smtps://smtp.gmail.com:465" \
52+ curl -sS --url " smtps://smtp.gmail.com:465" \
5253 --ssl-reqd \
5354 --user " $SPACE_EMAIL_SRC :$SPACE_EMAIL_PASS " \
5455 --mail-from " $SPACE_EMAIL_SRC " \
@@ -76,6 +77,9 @@ for DRIVE in $SPACE_CHECK_DRIVES; do
7677 [[ $LEN -gt $MAX_DRIVE_LEN ]] && MAX_DRIVE_LEN=$LEN
7778done
7879
80+ OUTPUT=" "
81+ FOUND_ISSUE=0
82+
7983# Check each drive
8084for i in " ${! DRIVE_LIST[@]} " ; do
8185 DRIVE=" ${DRIVE_LIST[$i]} "
@@ -102,14 +106,19 @@ for i in "${!DRIVE_LIST[@]}"; do
102106 else
103107 NAME=" ${DRIVE: 1} " # Assumes first char is `/`
104108 fi
105- printf " %-*s: %s/%s\n" " $MAX_DRIVE_LEN " " $NAME " \
106- " $FREE_HUMAN " " $TOTAL_HUMAN " >> " $SPACE_LOG "
109+ line=$( \
110+ printf " %-*s: %s/%s\n" \
111+ " $MAX_DRIVE_LEN " " $NAME " " $FREE_HUMAN " " $TOTAL_HUMAN " \
112+ )
113+ OUTPUT+=" $line \n"
107114
108115 # Do nothing if under capacity
109116 if [[ " $FREE_BYTES " -gt " $SPACE_LIMIT_BYTES " ]]; then
110117 continue
111118 fi
112119
120+ FOUND_ISSUE=1
121+
113122 # Send email alert
114123 BODY=" Low space warning: ${NAME} has ${FREE_HUMAN} /${TOTAL_HUMAN} free"
115124 SUBJ=" ${NAME} "
@@ -119,7 +128,15 @@ for i in "${!DRIVE_LIST[@]}"; do
119128 send_slack_message " $BODY "
120129
121130 for RECIPIENT in $SPACE_EMAIL_RECIPIENTS ; do
122- send_email_message " $RECIPIENT " " $SUBJ " " $BODY "
131+ send_email_message " $RECIPIENT " " ALMOST FULL: $SUBJ " " $BODY "
123132 done
124133
125134done
135+
136+ echo -e " $OUTPUT " >> " $SPACE_LOG "
137+
138+ if [[ " $SPACE_EMAIL_ON_PASS " == " true" ]] && [[ " $FOUND_ISSUE " == " 0" ]]; then
139+ for RECIPIENT in $SPACE_EMAIL_RECIPIENTS ; do
140+ send_email_message " $RECIPIENT " " Disk Space OK" " $OUTPUT "
141+ done
142+ fi
0 commit comments