Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I stumbled upon a script on the internet that monitors disk space and if it reaches a certain percentage being full it send an email. However, the problem I ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    6

    Scripting help...monitoring disk space..please

    Hi,
    I stumbled upon a script on the internet that monitors disk space and if it reaches a certain percentage being full it send an email. However, the problem I encountered was that one of the file system names are longer than usual so it expends over to the other columns and causes the other data to be put onto a second line. So the script no longer works when this is the case. does anyone know how to fix the script to take this into account?

    This is what I get when I run df-H. The first line goes onto a second line because of the file name so the script return incorrect information when I ask to print columns 5 and 1.


    Code:
    Filesystem             Size   Used  Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol00
                            77G   8.2G    65G  12% /
    /dev/sda1              104M    14M    86M  14% /boot
    none                   525M      0   525M   0% /dev/shm

    This is the script I'm using.


    Code:
    #!/bin/sh
    df -H | grep -vE '^Filesystem|none|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 10 ]; then
       echo "Running out of space \"$partition ($usep%)\" on $(hostname)" | mail -s "Alert: Almost out of disk space $usep" some@someone.net
    fi
    done

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this:

    Code:
    df -H | grep -vE '^Filesystem|none|cdrom' | 
    awk '
    NF<5{getline}
    $5>"10" && NF>5 {print "Running out of space "$1 " on "$5}'
    Regards

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    6
    Quote Originally Posted by Franklin52 View Post
    Try this:

    Code:
    df -H | grep -vE '^Filesystem|none|cdrom' | 
    awk '
    NF<5{getline}
    $5>"10" && NF>5 {print "Running out of space "$1 " on "$5}'
    Regards
    I just tried your code, and it seems like it just skips the first line if it's too long. On my file system I have an Use&#37; of 12, 14, and 0 but when I run your code I just get the second file system printed out: "Running out of space /dev/sda1 on 14%"
    I would like it to determine that /dev/mapper/VolGroup00-LogVol00 and /dev/sda1 are low on disk space for this example...

  4. #4
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Change 'df -H' to 'df -HP' and see if that helps.

    Vic

  5. #5
    Just Joined!
    Join Date
    Mar 2008
    Posts
    6
    Quote Originally Posted by vsemaska View Post
    Change 'df -H' to 'df -HP' and see if that helps.

    Vic
    Thanks so much! that did the trick!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...