Linux Forums - Linux Help,Advice & support community:LinuxSolved.com

Linux in General => Linux Development & Programming => Topic started by: ruthvik on September 18, 2014, 06:53:06 PM

Title: I need a script to send an email when disk space is full
Post by: ruthvik on September 18, 2014, 06:53:06 PM
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
Title: Re: I need a script to send an email when disk space is full
Post by: aktiwari4u on September 21, 2014, 04:44:22 PM
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




Title: Re: I need a script to send an email when disk space is full
Post by: tuxi on September 29, 2014, 07:15:56 AM
I think he is then supposed to add it in cron to get executed regularly ?
Title: Re: I need a script to send an email when disk space is full
Post by: aktiwari4u on November 18, 2014, 07:17:24 AM
yes it is desired ...