Check space of directories and send email if it has reached threshold limit


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check space of directories and send email if it has reached threshold limit
# 1  
Old 03-24-2010
Check space of directories and send email if it has reached threshold limit

Hi,

I need help in writing unix script for checking space of some directories on the system and also send an email when it reaches the threshold limit.

I have written the followng code;

Code:
 
#!/bin/ksh
ADMIN="me@somewhere.com"
# set alert level 80% is default
THRESHOLD=80
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 $THRESHOLD ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done

When I run the above code I get the following error;

dspace.ksh[15]: Iused: bad number
# 2  
Old 03-24-2010
Code:
df | sed -n '2,$s/\(.[^ \t]*\)\(.*\) *\(100%\|[89][0-9]%\)[ \t]*\(.*\)/\1 \3/p' | mail -s "partitions more than 80%" root

# 3  
Old 03-24-2010
Sorry, I could not understand

Hi Kurumi,

Sorry, I could not understand what was written and where in the code I could fit that. Can you please explain. Please bear with me as I am a beginner. Thanks.
# 4  
Old 03-24-2010
first check if this command is working for you:

Code:
df | sed -n '2,$s/\(.[^ \t]*\)\(.*\) *\(100%\|[89][0-9]%\)[ \t]*\(.*\)/\1 \3/p'

# 5  
Old 03-24-2010
df | grep "[89][0-99]%" | awk '{ print $1,"mounted on",$6,"has exceeded 80%"}' | mail -s "partitions more than 80%" user
# 6  
Old 03-25-2010
command is not working

Hi asalman,

I tried the following command;

Code:
df | grep "[89][0-99]%" | awk '{ print $1,"mounted on",$6,"has exceeded 80%"}' | mail -s "partitions more than 80%" user

There is no mail in my mail. Remember, I want this mail to be sent to my email which is on lotus notes and in gmail.

I then tried the following commang;

Code:
 
df | grep "[89][0-99]%"

and find that it is picking the records which are more than 80% but does not include the ones which are 100%. I want to include all records that have reached 80% to 100%.

Please let me know. 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

Merge Text with space into once cell and send email out

Please help!! This code works perfect but the only problem I am having is that is treats eg SQL Developer as separate cell/column which makes the formatting bad. I want to put SQL Developer in one cell. I attached a sample of how the output looks like. report.txt USERNAME OSUSER ... (5 Replies)
Discussion started by: lpoolfc
5 Replies

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

3. UNIX for Dummies Questions & Answers

How to confirm that I've reached the nproc limit?

Hi, I am getting the error su: cannot set user id: Resource temporarily unavailable. In limits.conf, it shows soft nproc 2047 for this user. ps H -u | wc -l shows 508 processes only. Linux flavour is Red Hat Enterprise Linux Server release 5.10 (Tikanga) Any advice will be much... (1 Reply)
Discussion started by: newbie_01
1 Replies

4. Shell Programming and Scripting

Help....script check status if see something then send email

autorep -m bogus Machine Name Max Load Current Load Factor O/S Status ___________ ________ ___________ ______ ________ ______ bogus --- --- 1.00 Sys Agent Online Status ______ Online Offline Missing Unqualified The "Status" always "Online". I like create a script execute run... (6 Replies)
Discussion started by: dotran
6 Replies

5. UNIX for Dummies Questions & Answers

httpd count exceeded threshold limit

Hello Everyone, I am new to this forum and also unix/linux. Our application today threw an alert whcih read as "The users active count on host has crossed the threshold limit of 50 and is standing at 65." This was although cleared when I restarted tomcat. But I am not sure why this count... (0 Replies)
Discussion started by: ykhati
0 Replies

6. UNIX for Dummies Questions & Answers

stunnell log file has reached its limit

Please help! I am really new to Linux, and my colleague who usually deals with these things isnt here to help me out. We are running Scalix mail services on CentOS 6.0. Email users with IMAP folders are getting an error message stating the server cannot be reached, however POP3 mail users are... (13 Replies)
Discussion started by: beckyboo
13 Replies

7. Shell Programming and Scripting

Check and compare disk space and email it

I am very new to Linux and learning to script. This is for one of my servers at work that I have to keep track off as far as disk space and how it is used. I have tried to go line by line but little things keep chewing me up. I would appreciate any and all help or advice, and Mutt is installed on... (3 Replies)
Discussion started by: sgtjkj
3 Replies

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

9. Shell Programming and Scripting

Script to check processes and send an email

I searched through the forum and couldn't quite find what I was looking for. I have a script that looks for a process "DW" to be running. If it is not it will email a notice to an account. I would like to add the functionality to have it also email a seperate notice if there is more that one of... (1 Reply)
Discussion started by: heprox
1 Replies

10. UNIX for Dummies Questions & Answers

Counting Files and send an email Notification if it exceeds a limit

Hi, I am trying to write a script to Count Files in a directory located on a remote server and send an email Notification if it exceeds a limit. The code given below doesnot check the condition and sends the mail everytime irrespective of the condition. I have put this script in the cron. Can... (10 Replies)
Discussion started by: amitsayshii
10 Replies
Login or Register to Ask a Question