LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2014, 02:47 PM   #1
ruthvikbittu
LQ Newbie
 
Registered: Sep 2014
Posts: 2

Rep: Reputation: Disabled
Lightbulb I need a script to send an email when disk space is full


Hi ,
I need a script and detailed procedure how to send an 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
 
Old 09-18-2014, 02:59 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,921

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by ruthvikbittu View Post
Hi ,
I need a script and detailed procedure how to send an 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
We will be glad to HELP you, but we aren't going to write the script for you...so post what you've written/done on your own, and tell us where you're stuck. If you already have some scripts, which one are you going to use? What are you having problems with??

And if you also need to configure a mail system, you need to tell us what version/distro of Linux you're using, along with details about your environment. And you may want to contact a moderator to have them move this, since "Wireless Networking" isn't really related to a script or email configuration on a server.
 
Old 09-18-2014, 06:49 PM   #3
pwalden
Member
 
Registered: Jun 2003
Location: Washington
Distribution: Fedora FC23, Raspbian, Ubuntu Precise via Chrome/Crouton
Posts: 350

Rep: Reputation: 41
He is a sample of a script I wrote to send out my IP address daily when I travel.

It uses mutt and my ISP's SMTP server. It is triggered daily by a cronjob. So your script will differ depending on your particular mail and cron set up.

Code:
#!/bin/bash

#ipaddsrc="http://bot.whatismyipaddress.com/"
ipaddsrc="http://api.ipify.org"

if [ -f $HOME/onholiday ]
then
   export ipaddress=$( wget --quiet -O - "$ipaddsrc" )
   echo emailing: $ipaddress
   echo $ipaddress | mutt -s 'Current IP Address' myaddr@myisp.net
   echo remove file onholiday to stop messages.
fi
 
Old 09-19-2014, 12:11 PM   #4
ruthvikbittu
LQ Newbie
 
Registered: Sep 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi, we are using Red Hat Enterprise Linux Server release 5.5 .
I have the below script, I don't know how to configure. I have saved this script in root as disk_check.sh, and added to crontab, but i am not getting even the disk space reaches 100%. please help me.

Code:
#!/bin/ksh
ADMIN="ruthvikbittu@gmail.com"
# set alert level 88% is default
ALERT=88
df | grep -E "Filesystem|tmpfs|cdrom" | awk '{ print $5 " " $1 }' | while read output;
do
#echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep" $ADMIN
fi
 
Old 09-19-2014, 12:19 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
That's because of the 'grep -E "Filesystem|tmpfs|cdrom"'

You're explicitly filtering out all filesystems and only returning the title bar and specs for tmpfs or cdrom mount points, I'm pretty sure that's not what you want. Maybe you meant to put a "-v" in there to have grep return all lines EXCEPT Filesystem, tmpfs, or cdrom? You'll also need the "-P" flag to df to keep it from wrapping lines.

With those changes it should be fine. You are missing a "done" to close out the while loop though.

Code:
$ ALERT=50
$ df -P | grep -vE "Filesystem|tmpfs|cdrom" | awk '{ print $5 " " $1 }' | while read output;
> do
>    usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
>    partition=$(echo $output | awk '{ print $2 }' )
>    if [ $usep -ge $ALERT ]; then
>       echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
>    fi
> done
Running out of space "/dev/sda1 (68%)" on euclid as on Fri Sep 19 10:25:26 MDT 2014
Running out of space "/dev/md127p2 (60%)" on euclid as on Fri Sep 19 10:25:26 MDT 2014
I pulled out the "mail" bit for testing here.

Last edited by suicidaleggroll; 09-19-2014 at 12:28 PM.
 
1 members found this post helpful.
Old 09-22-2014, 09:03 AM   #6
nisagnel
LQ Newbie
 
Registered: Mar 2010
Location: India
Distribution: Centos
Posts: 28

Rep: Reputation: 2
its great.Thank you all.

Last edited by nisagnel; 09-22-2014 at 09:05 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Strange error for disk space alert email script Vi_rod Linux - Newbie 7 12-16-2011 07:09 AM
[SOLVED] hard disk space email notification - SOLARIS 10 - script dlugasx Solaris / OpenSolaris 1 06-24-2010 07:49 AM
[SOLVED] Linux base shell script with java which check the disk space and send mail to my id dhirendrs Linux - Newbie 2 06-14-2010 12:50 PM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 02:12 PM
Looking for easy way to send warning email when disk near full. bdb4269 Linux - Software 2 11-02-2006 08:44 PM


All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration