LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2012, 09:47 AM   #1
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Rep: Reputation: 9
Get only Highest disk space


Hi There,
RHEL 5.6

I want a script that returns only the highest disk space. So far I have :

PHP Code:
#!/bin/sh
df=`df -Pl | grep "^/dev" | awk '{print $5, $6}' | sed "s/%//"`
echo 
"$df| while read percent fs
do
    if [ 
$percent -ge 90 ] ; then
       
echo "$percent% -- Disk $fs"
    
fi
done 
Result :

PHP Code:
94% -- Disk /staging
90
% -- Disk /u02 
So I only want 94% -- Disk /staging

Please help
 
Old 05-14-2012, 10:04 AM   #2
blue_print
Member
 
Registered: May 2010
Location: In world
Distribution: RHEL, CentOS, Ubuntu
Posts: 275
Blog Entries: 3

Rep: Reputation: 50
In your if loop change ge to gt

Quote:
if [ $percent -ge 90 ] ; then
to

Code:
if [ $percent -gt 90 ] ; then
 
1 members found this post helpful.
Old 05-14-2012, 10:22 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Since you should sort the output and get only the first or the last line (depending on ascending or descending order) you might try something simpler as:
Code:
#!/bin/sh
#
df -Pl | sort -k5n | awk 'END{printf "%s -- Disk %s\n", $5, $6}'
In any case, what if two disks have the same percentage? Do you want to print them both?
 
1 members found this post helpful.
Old 05-15-2012, 06:13 AM   #4
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Original Poster
Rep: Reputation: 9
Thanks guys, both your posts were very helpful.
@colucix : No, only one then.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition space and disk space usage and free don't match nsic Linux - Newbie 3 02-22-2013 01:57 PM
hard disk partitioning/I am out of space /how to increase linux space? RMLinux Red Hat 8 09-05-2008 01:33 PM
add space to / when from spare space on disk ctsiow Linux - General 4 11-07-2007 08:55 AM
Cedega "Disk space required for the installation exceeds available disk space" Solved Spewdemon LinuxQuestions.org Member Success Stories 1 10-18-2007 07:19 PM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 04:58 PM


All times are GMT -5. The time now is 05:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration