Check the partition size on server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check the partition size on server
# 1  
Old 07-20-2011
Check the partition size on server

Dear All,


I need notification mail from server while device size crossed 80% approximately.I tried following shell .its working fine when the device name like /dev/sdc1 etc.Its not working in LVM name.For example

Script:

Code:
#!/bin/sh
echo "Storage server space details";
df -H | grep -vE '^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 80 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" user1@domainname.com
  fi
done

----
>>Its working fine while following device name available

Code:
[root@Server1 test]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              95G  8.2G   82G  10% /
/dev/sda12            9.5G  3.5G  5.6G  39% /home

>> Its not working for like below mention name
Code:
#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/device1/LVM_LGroup1
                      6.8G  791M  5.7G  13% /
/dev/sda1             996M   53M  892M   6% /boot
tmpfs                1006M     0 1006M   0% /dev/shm
/dev/device2/LVM_LGroup2
                      6.8G  163M  6.3G   3% /home

How to filter with entire LVM_LVGrou1.please reply
# 2  
Old 07-20-2011
Because some input spans lines so join the lines together and then run your script...
# 3  
Old 07-20-2011
How about this?

Code:
 
df -h | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | awk 'int(substr($5,1,index($5,"%")-1))>=80'


Last edited by panyam; 07-20-2011 at 12:58 PM.. Reason: changed to greater than condition
This User Gave Thanks to panyam For This Post:
# 4  
Old 07-22-2011
Thanks pan yam,

This code "df -h | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | awk 'int(substr($5,1,index($5,"%")-1))>=80'" is useful for me.

>>But any possible to get full string through my script in
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'
# 5  
Old 07-22-2011
Did not get you fully on what you mean.

Try below:

Code:
#!/bin/sh
echo "Storage server space details";
df -H | awk 'NF==1{a=$0;next} NF >1 { a=(a?a" "$0:$0) ; print a;a=""}' | grep -vE '^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 80 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" user1@domainname.com
  fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check size of a partition

hi want to schedule a script for displaying the size of the partiition. For example df -g /dev/fslv03 2000.00 535.43 74% 179943 1% /nvbkp we have several mount point like this but i want to schedule script to display size of the above mount point only. Thanks Ankit (4 Replies)
Discussion started by: ankit2012
4 Replies

2. Shell Programming and Scripting

Check the size of the file on different server

Hello, I have two servers A and B, My script is written on Server A. I am picking up the file say "abc.txt" from Server B using sftp command and putting it in a directory at Server A. Now the catch is, If the file size of "abc.txt" is greater thn the available size on Server A, thn an email... (5 Replies)
Discussion started by: Prashant Jain
5 Replies

3. UNIX for Advanced & Expert Users

Check the size of the file on different server

Hello, I have two servers A and B, My script is written on Server A. I am picking up the file say "abc.txt" from Server B using sftp command and putting it in a directory at Server A. Now the catch is, If the file size of "abc.txt" is greater thn the available size on Server A, thn an email... (1 Reply)
Discussion started by: Prashant Jain
1 Replies

4. HP-UX

Increase of partition Size In HP-UX

Experts, I want to know how to increase partion size in Hp-ux.Actually we installed oracle in separate part ion.As increase of database went to 99% :eek:.What ever data which is in it is important.so i dont want to delete any data in that partion.Now the size of that is 250 GB.I want the same to... (2 Replies)
Discussion started by: naveennella
2 Replies

5. UNIX for Dummies Questions & Answers

Size of swap partition during installation

Greetings. I've been into computers since the '80s, but this is my first attempt at Linux. I'm installing Debian Lenny on a PIII 733 with 10GB hard drive and 512MB Ram. I intend to use the machine primarily as a development server, with things like mySQL, Apache, php, etc. I don't really want... (22 Replies)
Discussion started by: fguy
22 Replies

6. Linux

primary partition size

hi I am trying to create primary,extended and logical partitions. when I try to create a primary partition, I can give it maximum 1027M (1gb). Why? (9 Replies)
Discussion started by: tjay83
9 Replies

7. Shell Programming and Scripting

how to connect to server with ssh to check process size

Hello i have to connect to 11 servers to check the process size on every server. how to that with shell scripting using ssh regards (7 Replies)
Discussion started by: mogabr
7 Replies

8. UNIX for Dummies Questions & Answers

Increasing the Size of the Samba Partition

Hi, Is there any command to increase the size of the samba partition when the samba share is online?? Regards Arun (1 Reply)
Discussion started by: Arun.Kakarla
1 Replies

9. Solaris

Partition size calculations

Hi guys, I have an V100 server and I'm about to install solaris 8 on it (I have 10 on currently but most of my work is on 8 so I'm going to that). It would be easy for me to post system specs and get a recommendation, but what I'd like is to know HOW to calculate so that I can set up other... (1 Reply)
Discussion started by: Stin
1 Replies

10. Solaris

inrease partition size

hi, i created a partition c1t0d0s5 sized 10gb and a soft partition on it. now i want to expand this size to 15gb (my hard disk is 36gb). anybody show me the way to do that, please. here are the outputs of the df and format commands: # df -h Filesystem size used avail capacity ... (5 Replies)
Discussion started by: xuc_xich_duc
5 Replies
Login or Register to Ask a Question