Add disk-warn.sh
This commit is contained in:
commit
2180265d4c
1 changed files with 28 additions and 0 deletions
28
disk-warn.sh
Normal file
28
disk-warn.sh
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
# Purpose: Monitor Linux disk space and send an email alert to $ADMIN
|
||||
#ALERT=90 # alert level
|
||||
ALERT=90
|
||||
ADMIN="neshura@neshweb.net" # dev/sysadmin email ID
|
||||
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read -r output;
|
||||
do
|
||||
echo "$output"
|
||||
usep=$(echo "$output" | awk '{ print $1}' | cut -d'%' -f1 )
|
||||
partition=$(echo "$output" | awk '{ print $2 }' )
|
||||
lockname=$(echo $partition | tr / _);
|
||||
if [ $usep -ge $ALERT ]; then
|
||||
if test -f "./$lockname.lock";
|
||||
then echo "Found lockfile - Cancel mail";
|
||||
else
|
||||
touch "./$lockname.lock"
|
||||
{
|
||||
echo "TO: $ADMIN"
|
||||
echo "Subject: Alert: Disk spage usage at $usep%/$ALERT%"
|
||||
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
|
||||
} |
|
||||
ssmtp -F"Jellyfin" "$ADMIN"
|
||||
fi
|
||||
else
|
||||
if test -f "./$lockname.lock"; then rm "./$lockname.lock"
|
||||
fi
|
||||
fi
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue