LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-07-2010, 10:44 AM   #1
karlochacon
Member
 
Registered: Dec 2006
Posts: 107

Rep: Reputation: 17
Filesystem percentage and highlight


hi

how can I show only the filesystems like root, home, var and so on and not to show /boot and /dev/shm using df ?

Code:
Filesystem             Size   Used  Avail Use% Mounted on
/dev/mapper/VolGroup00-root
                       123G   2.2G   114G   2% /
/dev/sda1              104M    12M    87M  12% /boot
tmpfs                  1.1G      0   1.1G   0% /dev/shm
/dev/mapper/VolGroup00-home
                       3.1G    73M   2.8G   3% /home
/dev/mapper/VolGroup00-tmp
                       5.1G   145M   4.7G   4% /tmp
/dev/mapper/VolGroup00-usr
                       5.1G   1.8G   3.1G  37% /usr
/dev/mapper/VolGroup00-var
                       3.1G   757M   2.2G  27% /var

and second is there any way to highlight when the filesystems usage is equal or greater that 80%... something like picture below.

so basically I need to remove no real filesystems and highlight when the % is >=80

thanks a lot
Attached Thumbnails
Click image for larger version

Name:	high.PNG
Views:	9
Size:	7.2 KB
ID:	3286  
 
Old 04-07-2010, 10:51 AM   #2
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: *buntu, Vector
Posts: 499

Rep: Reputation: 102Reputation: 102
You can list only certain filesystems by specifying them, eg

df -h /dev/sda1 /dev/sda2

If your filesystems change, that's no good. You can probably pipe the output of df through grep, searching for lines that don't have the filesystems you want to exclude. But that may not play nicely with watch if you're using it.

As for highlighting, I don't know.
 
Old 04-07-2010, 11:16 AM   #3
karlochacon
Member
 
Registered: Dec 2006
Posts: 107

Original Poster
Rep: Reputation: 17
I think I have it thanks for your idea

Code:
[root@----- ~]# df -h | grep -v boot | grep -v shm
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-root
                      4.8G  1.3G  3.2G  29% /
/dev/mapper/rootvg-home
                      2.9G 1023M  1.7G  38% /home
/dev/mapper/rootvg-tmp
                      4.8G  146M  4.4G   4% /tmp
/dev/mapper/rootvg-usr
                      4.8G  3.3G  1.2G  81% /usr
/dev/mapper/rootvg-var
                      2.9G  1.2G  1.5G  44% /var
now any idea how to highlight the the filesystem as my picture above when it reaches 80% o more

thanks a lot
 
Old 04-07-2010, 11:25 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
You could probably use awk or sed to catch the number, then simple shell scripting ("man bash", then look for -le, -gt, -eq etc.).

You can print colors using a simple echo command and ansi codes.

But, being that said, when you have to pipe a thousand commands together it's probably time to look for an alternate solution. If I needed to do this I'd probably hack a bit into the pydf (not regular df) source code. If you know a little python it shouldn't be too difficult to add the desired functionality, since pydf already does coloring. Then you would have a probably more portable and less error-prone solution.
 
Old 04-07-2010, 11:35 AM   #5
karlochacon
Member
 
Registered: Dec 2006
Posts: 107

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by i92guboj View Post
You could probably use awk or sed to catch the number, then simple shell scripting ("man bash", then look for -le, -gt, -eq etc.).

You can print colors using a simple echo command and ansi codes.

But, being that said, when you have to pipe a thousand commands together it's probably time to look for an alternate solution. If I needed to do this I'd probably hack a bit into the pydf (not regular df) source code. If you know a little python it shouldn't be too difficult to add the desired functionality, since pydf already does coloring. Then you would have a probably more portable and less error-prone solution.

yes I should have known that this requires a lot of time - the color or highlight thing - I am going to try the awk sed commands if someone can give a me a hand that would be great

Last edited by karlochacon; 04-07-2010 at 11:38 AM.
 
Old 04-07-2010, 11:48 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
You will have to process the lines one by one. Provided you do that, you could do something like:

Code:
df -h -P | grep -v boot | grep -v shm | grep -v Used | \
  while read line; do
    echo "Processing this string: \"$line\""
    N=$(echo $line | sed -e 's/%.*//' -e 's/.* //')
    echo "N=$N";
    # Now you will have to check if N is greater or lesser than a given number.
    # Then, if it's greater than whatever, print the ansi string for a given color + $line
    # else just print $line
  done
 
Old 04-07-2010, 09:03 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
So a little poking around got me:

Code:
df -h | awk 'NR > 1 && $5 > 80{gsub($5, "\033[0;31m"$5"\033[0m")}!/boot|shm/{ print }'
 
  


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
what percentage of queries come from indians? kevmcool General 56 04-01-2010 10:46 PM
gprof percentage numbers mllouay Linux - General 0 08-28-2008 11:37 AM
Percentage of all Code Written in C jhwilliams Programming 1 09-10-2007 12:11 AM
Free memory in percentage kinetik Programming 6 03-31-2006 01:16 AM
What is the percentage of each distro in use ? newlin Linux - General 1 08-03-2003 05:41 PM


All times are GMT -5. The time now is 06:48 PM.

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