email warning script for disk usage


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers email warning script for disk usage
# 1  
Old 02-14-2009
Question email warning script for disk usage

I'm trying to monitor disk usage, using cron to run a script to email me when disk capacity exceeds 66%. When I use df (actually, "df -k" because I find the format useful), disk capacity shows as field 5. However, that field includes a % which is confusing my ">" comparison to include a warning.

My goal: monitor disk usage every hour (cron: 0 * * * *), take disk usage info from "df -k" and if disk usage exceeds 2/3 (66%) email me a warning.

There are many ways to skin this cat. If you have a more efficient way, I'm open to suggestions.

Thanks.
# 2  
Old 02-14-2009
i have something like this in my shell's start up file, so every time i log on, i will get a warning if it goes over 90%....customize it to your liking:

Code:
#### check disk space on filesystems listed
filesystems=(/ /boot /storage1)
for fs in ${filesystems[@]}; do
    disk_space=`df -h | grep -E $fs$ | awk '{print $(NF-1)}'`
    max_space="90"
    disk_space=${disk_space:-$((max_space-1))}
    [[ "${disk_space%'%'}" -ge "$max_space" ]] && { clear ; echo -e "\nWARNING...DISK SPACE ON \"$fs\" IS AT $disk_space\n"; }
done
unset filesystems fs disk_space max_space
####

In the array "filesystems" i have the mount point of every filesystem i want to check...

I guess the important part for you is the "${disk_space%'%'}" part, which will strip off that '%' sign
# 3  
Old 02-15-2009
Thanks. That got me off and running. I found a slightly different way of getting rid of the % sign, but there must be some elementary syntax error I'm making:

$ df -k | sed 's/%//' | awk if ($5 > 66) {print $0} | mailx -s "WARNING: Disk usage exceeded limit" invisibleman@domain.com

Error message: syntax error near unexpected token `($' For clarity, that's ` ( $ '

Any ideas, anyone?
# 4  
Old 02-15-2009
Try this way, as the output of df will multiple lines, so need to exclude and get only filesystem mount point...

df -k | sed 's/%//'|grep -vE "^/dev|^Filesystem" |awk '{if ( $4 > 43 ) print $0 }'

Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Disk usage monitoring and record the disk used in last 24 hour

HI I am Trying to edit the below code to send email every day with difference of disk utilized in for last 24 hours but instead getting same usage everyday. can you please help me to point out where my calculation is going wrong. Thank you. ================= #!/bin/bash TODAY="at $(date... (0 Replies)
Discussion started by: Mi4304
0 Replies

2. UNIX for Beginners Questions & Answers

UNIX cluster disk usage report generation for yesterday & today and email

HI Team, I am trying to create a shell script to generate a yesterday and today report to compare and email in daily basis. can you please help me on the same. #!/bin/bash #Author: ******************* #Description: This script will return the following set of system information: ... (2 Replies)
Discussion started by: Mi4304
2 Replies

3. Shell Programming and Scripting

Generate disk space usage email alert

hi all members I have a shell script to generate disk space usage email alert if threshold is more than 80 %, now the requirement changed to keep sending alert emails for every 5% incremental usage ........ Any help would be greatly appreciated. ex - 80% , 85% ,90%,95%,100% we should get an... (6 Replies)
Discussion started by: anil529
6 Replies

4. Shell Programming and Scripting

Send Disk Space Usage Status via email

Hi Guys, Is there any way I can write a script that sends DISK SPACE USAGE STATUS via email once a week? Thanks, (5 Replies)
Discussion started by: g4v1n
5 Replies

5. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

6. Shell Programming and Scripting

shell script to alert cpu memory and disk usage help please

Hi all can any one help me to script monitoring CPU load avg when reaches threshold value and disk usage if it exceeds some % tried using awk but when df -h out put is in two different lines awk doesnt work for the particular output in two different line ( output for df -h is in two... (7 Replies)
Discussion started by: robo
7 Replies

7. Shell Programming and Scripting

script to monitor disk space usage

Some times my disk space is used upto 100% due to the application logs . So this script is to monitor the disk space usage and wall message to the users about the disk space usage if it exceeds the limit set in the script. Here for example the limit is set to 80%. This job is added in cron to... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

8. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

9. Shell Programming and Scripting

shell script to send email with usage of space in the directory as description :

shell script to send email with usage of space in the directory as description : Please any one help me in writing a script to send email with usage of space in the directory as description . (3 Replies)
Discussion started by: sakthifire
3 Replies

10. Shell Programming and Scripting

Need to send email on HIGH Disk usage

Hi Guys I am looking for a python / PERL script which will send me email when ever my disk becomes more than 90% full. By the way my OS is Win XP. If anybody have already has written same type of script or something very similar kind of script, that will also be very helpful. Thanks... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question