-
Notifications
You must be signed in to change notification settings - Fork 6
/
check_partition_space.sh
executable file
·50 lines (43 loc) · 1.32 KB
/
check_partition_space.sh
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
#!/bin/bash
#
# Author :Julio Sanz
# Website :www.elarraydejota.com
# Email :[email protected]
# Tested in :Debian Wheezy/Jessie, RHEL/CentOS/Fedora 6/7
# Description :Script to check used space in a partition and send email in case
# it exceeds the threshold value
# Usage :1- chmod +x check_partition_space.sh
# 2- ./check_partition_space.sh
# License :GPLv3
#
#
# VARIABLES
#
mail="your_email"
partition="/path/to/partition/to/check"
# Once % occupation exceeds threshold value, an email is sent to notify
threshold_value="80"
# NOTE: in your system, check if the column 4 matches with the percentage number.
# On some systems is column 4 and in other, column 5
used_space=$(df -h $partition | head -3 | tail -1 | tr -s "%" " " | awk '{print $4}')
#
# FUNCTIONS
#
chk_partition_space(){
if [ "$used_space" -gt "$threshold_value" ];then
echo "ALERT!, Disk partition $partition occupation > $threshold_value % in $(hostname)" \
| mail -s "ALERT!, Disk partition $partition occupation > $threshold_value % in $(hostname)" "$mail"
fi
}
how_to_use(){
echo "This script is intended to work without parameters"
echo "Just launch it -> ./check_partition_space.sh"
}
#
# MAIN
#
if [ $# -ne 0 ];then
how_to_use
else
chk_partition_space
fi