-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiskalert
executable file
·73 lines (52 loc) · 1.7 KB
/
diskalert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Script Name: diskalert
# Author: Matt McKinnon
# Date: 7th June 2016
# Description:
# This script will email when diskspace is high.
MAILTO="[email protected]"
MAILFROM="[email protected]"
THISSERVER=$(hostname -f)
SMTP="comprofix-com.mail.protection.outlook.com"
LOGFILE="/var/log/diskalert.log"
THISSERVER=$(hostname -f)
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
declare -a DEVICES
index=0
startlogging
for i in $( df -h | grep "/dev/" | grep -v tmpfs | awk '{print $1}' );
do
DEVICES[$index]=$i
let "index += 1"
done
for i in ${DEVICES[@]};
do
let space=`df -Pk $i | grep -v ^File | awk '{printf ("%i", $5) }'`
if [ $space -le 89 ]
then
echo "$(date) [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE
fi
if [ $space -ge 90 ]
then
echo "$(date) [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE
echo "
Hello,
You are running out of disk space on $THISSERVER.
Your $i is currently using $space% of disk space.
See the logfile for more info: vim $LOGFILE
Regards, " >/tmp/diskalertmail.msg
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space" -m "$(cat /tmp/diskalertmail.msg)" -q
echo "$(date) [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
fi
done
stoplogging