473,657 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scripting help...monitori ng disk space

1 New Member
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 3509
kvkrishna
1 New Member
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
optikknight
1 New Member
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_preformat ted 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
1856
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
2870
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 Maximum Minimum %Disk Time 1 2.74 24.932 0 Current Disk Queue Length 10 0.090 6 0 Buffer cache hit ratio 1 99.752 99.752 99.751
1
1552
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 backups and Transaction Log dumps, more critical boxes have additional hourly transaction dumps. The database maintenance should be deleting any backups more than 2 days old (Should have been picked up by system backups and moved to SAN by then).
1
5624
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 after using the Directory class... There seems to be a way to load the System Management Object with string path ( 8 overloads ), but every time I try a variation it crashes. Any ideas ? Thanks Scripting.FileSystemObject FSO = new
1
1327
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 server doesn't support php only asp. Thanks Laurie
4
4613
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 == 0: m = re.search('((#.+\r\n){20,25})(\s.*)', s.before) #<---------- MY PROBLEM
4
11110
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 length is 129M or more for each file upload. I have 2 files upload at the same time. Therefore, I set the timeout is 20min and the size of file upload is 390MB (400,000 KBytes).
3
3691
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 http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html .. Please suggest some modification to the program so that i can detect changes to ALL the drives (to detect changes on c:\ set path_to_watch = "." to "c:\\" ...
7
8830
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 Scripting Runtime Library, you can retrieve information related to Drives, Folders, Files, and Text Files and set/retrieve certain Attributes of Drives, Folders, Files, and Text Files. Through Methods exposed by this Library, you can also manipulate...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.