473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Scripting help...monitoring disk space

1
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.


Expand|Select|Wrap|Line Numbers
  1. Filesystem             Size   Used  Avail Use% Mounted on
  2. /dev/mapper/VolGroup00-LogVol00
  3.                         77G   8.2G    65G  12% /
  4. /dev/sda1              104M    14M    86M  14% /boot
  5. none                   525M      0   525M   0% /dev/shm
  6.  

This is the script I'm using.


Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. df -H | grep -vE '^Filesystem|none|cdrom' | awk '{ print $5 " " $1 }' | while read output;
  3. do
  4.    #echo $output
  5.    usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  6.    partition=$(echo $output | awk '{ print $2 }' )
  7.    if [ $usep -ge 10 ]; then
  8.    echo "Running out of space \"$partition ($usep%)\" on $(hostname)" | mail -s "Alert: Almost out of disk space $usep" some@someone.net
  9. fi
  10. done
Mar 13 '08 #1
2 3492
Hi,
I use the below to monitor the disk space....
Expand|Select|Wrap|Line Numbers
  1. df -kt | grep "%" | grep "^/dev" >/tmp/file_sys.txt
  2. chmod 755 /tmp/file_sys.txt
  3. Flag=0
  4. while read LINE
  5. do
  6.         pcnt=`echo $LINE | cut -d"%" -f1 | awk '{print $NF}'`
  7.         f_sys=`echo $LINE | cut -d"%" -f2 | awk '{print $NF}'`
  8.         if [ $Flag -eq 0 ]
  9.         then
  10.         if [ $pcnt -ge 80 ] && [ $pcnt -le 100 ]
  11.         then
  12.                 echo $dashes >/tmp/`hostname`_alert.txt
  13.                 echo "The below file systems need house keeping.....!" >>/tmp/`hostname`_alert.txt
  14.                 echo $dashes >>/tmp/`hostname`_alert.txt
  15.                 #echo "File System $f_sys is $pcnt%"
  16.                 Flag=1
  17.         else
  18.                 Flag=0
  19.         fi
  20.         fi
  21.         if [[ $Flag -eq 1 ]]
  22.         then
  23.                 if [ $pcnt -ge 80 ] && [ $pcnt -le 100 ]
  24.                 then
  25.                         echo "File System $f_sys is $pcnt%" >>/tmp/`hostname`_alert.txt
  26.                 fi
  27.         fi
  28. done </tmp/file_sys.txt
  29. if [ -f /tmp/`hostname`_alert.txt ]
  30. then
  31.         if [ -s /tmp/`hostname`_alert.txt ]
  32.         then
  33.                 #cat /tmp/`hostname`_alert.txt
  34.                 mail_subject="ITRM:Alert from vista70"
  35.                 mail_file=/tmp/`hostname`_alert.txt
  36.                 mail_recp="abc@xyz.com abc@xyz.com abc@xyz.com" 
  37.                 mailx -s "$mail_subject" $mail_recp < $mail_file
  38.         fi
  39. fi
  40.  
Give me output as:
+-----------------------------------------------------------------------------+
The below file systems need house keeping.....!
+-----------------------------------------------------------------------------+
File System /vandata02 is 81%
File System /datafi01 is 84%
File System /data4 is 93%
File System /vanfi is 82%
File System /vandev is 91%
File System /VANPOC is 91%
File System /datauat01 is 88%
File System /datauat02 is 87%
File System /datahotfix01 is 96%
File System /datavanpc01 is 82%


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.


Expand|Select|Wrap|Line Numbers
  1. Filesystem             Size   Used  Avail Use% Mounted on
  2. /dev/mapper/VolGroup00-LogVol00
  3.                         77G   8.2G    65G  12% /
  4. /dev/sda1              104M    14M    86M  14% /boot
  5. none                   525M      0   525M   0% /dev/shm
  6.  

This is the script I'm using.


Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. df -H | grep -vE '^Filesystem|none|cdrom' | awk '{ print $5 " " $1 }' | while read output;
  3. do
  4.    #echo $output
  5.    usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  6.    partition=$(echo $output | awk '{ print $2 }' )
  7.    if [ $usep -ge 10 ]; then
  8.    echo "Running out of space \"$partition ($usep%)\" on $(hostname)" | mail -s "Alert: Almost out of disk space $usep" some@someone.net
  9. fi
  10. done
Mar 14 '08 #2
I've occasionally had the same problem... (And yes, I know I'm waking a dead thread. I figured I'd share my solution anyway.)

Here's my script for the same purpose:
df.cron

It assumes all lines not containing a '%' are wrapped, and pulls the next line. Example output:


Expand|Select|Wrap|Line Numbers
  1. Nearly full filesystems:
  2. Filesystem               Size  Used  Avail  Use%  Mounted-on
  3. /dev/mapper/System-home  100G  69G   26G    73%   /home
  4. /dev/hda6                38G   34G   2.3G   94%   /mnt/unsafe

(The write_preformatted call is a routine from the included lib, in the linked script.)

The more interesting parts, for text processing:

Expand|Select|Wrap|Line Numbers
  1. df -h > $filesystems
  2. sed '1d; /%/! { N; s/[\n\t]/ /; }' $filesystems | grep -E '([7-9][0-9]|[0-9]{3})%' > $filesystems.2
Jun 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jay Blanchard | last post by:
-----Original Message----- From: Moritz Steiner =20 Sent: Wednesday, July 16, 2003 10:46 AM To: Jay Blanchard Subject: AW: monitoring I want to see: Number of queries =20
1
by: Peter Ang | last post by:
I was wondering if the CPU is the bottleneck. Hence I used the Performance Monitor to look up some values. Here are the results. Counter Scale Average ...
1
by: Oddsavant | last post by:
Greetings, I'm looking for a little guidance. I work for a medium sized bank with about 20 SQL servers in 2 locations. We have two backup schemes - Less critical SQL boxes have nightly DB...
1
by: andrewcw | last post by:
I have used System.Management in the past to extract and walk thru drives & check their type. I can also do it with COM's FileSystemObject. Here I am trying to just use the Management Object...
1
by: laurie | last post by:
Hi. Does anyone know of a simple asp script that can check free disk space and send an email to someone when low disk space occurs? I am not familiar with asp. I am from a php background but our...
4
by: jonathan.sabo | last post by:
I have a pexpect script to walk through a cisco terminal server and I was hoping to get some help with this regex because I really suck at it. This is the code: index = s.expect() if index...
4
by: bienwell | last post by:
Hi all, I developed an web page in ASP.NET to upload file into the server. In the Web.config file, I declared <httpRuntime executionTimeout="1200" maxRequestLength="400000" /> The MAX...
3
by: rohit | last post by:
hi i want to detect all file change operations(rename,delete,create....) on ALL THE DRIVES of the hard disk using the method ReadDirectoryChanges API , i.e program no. 3 in the webpage...
7
ADezii
by: ADezii | last post by:
The next series of Tips will involve the Microsoft Scripting Runtime Library (Scrrun.dll). This Library is, in my humble opinion, one of the most useful and practical Libraries ever created. With the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.