November 22, 2024, 07:15:03 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: I need a script to send an email when disk space is full  (Read 14032 times)

Offline ruthvik

  • New Member
  • Posts: 1
I need a script to send an email when disk space is full
« 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

Offline aktiwari4u

  • LST CareTaker
  • Crescent
  • *****
  • Posts: 161
    • http://aktiwari4u.tk/
Re: I need a script to send an email when disk space is full
« Reply #1 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





Offline tuxi

  • Linux Noob !
  • *
  • Posts: 20
Re: I need a script to send an email when disk space is full
« Reply #2 on: September 29, 2014, 07:15:56 AM »
I think he is then supposed to add it in cron to get executed regularly ?

Offline aktiwari4u

  • LST CareTaker
  • Crescent
  • *****
  • Posts: 161
    • http://aktiwari4u.tk/
Re: I need a script to send an email when disk space is full
« Reply #3 on: November 18, 2014, 07:17:24 AM »
yes it is desired ...