Linux in General > Linux Development & Programming
I need a script to send an email when disk space is full
(1/1)
ruthvik:
Hi ,
I need a script and detailed procedure how to send an email automatically when the disk space is full in my Linux machine.
I have some scripts taken from Internet but I don't how to configure my email in the Linux box. Please help me
aktiwari4u:
there are many you may try anyone ...
here is one
#!/bin/bash
ADMIN=yermail@yerdom.com
ALERT=90
df -H | grep -vE 'abc:/xyz/pqr | tmpfs |cdrom|Used' | awk '{ print $5 " " $1 }' | while read output; do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
echo $usep
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "Alert: Almost out of disk space $usep"
df -H | mail -s "Alert: out of disk space $usep" $ADMIN
fi
done
you may try this or this one ...
message=$(awk -v ALERT="$ALERT" '
NR == 1 {next}
$1 == "abc:/xyz/pqr" {next}
$1 == "tmpfs" {next}
$1 == "/dev/cdrom" {next}
1 {sub(/%/,"",$5)}
$5 >= ALERT {printf "%s is almost full: %d%%\n", $1, $5}
')
if [ -n "$message" ]; then
echo "$message" | mail -s "Alert: Almost out of disk space" "$ADMIN"
fi
tuxi:
I think he is then supposed to add it in cron to get executed regularly ?
aktiwari4u:
yes it is desired ...
Navigation
[0] Message Index
Go to full version