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 11-25-2012, 02:35 AM   #1
1300
Member
 
Registered: Nov 2011
Posts: 45

Rep: Reputation: Disabled
Exclamation grep df -h to get greater than 90%


I have a monitoring tool which collects all kind of information from almost 60 RHEL servers and gather it in one directory/server

I want to grep disk info from all files and print FileSystems greater than 90% for faster alerting

I think I didn't get the special character thing in Linux properly !!
 
Old 11-25-2012, 02:42 AM   #2
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,829

Rep: Reputation: 257Reputation: 257Reputation: 257
Grep doesn't solve inequalities. It only performs OR logic.

---------- Post added Nov 25th, 2012 at 02:43 ----------

I think what you want is PERL or awk.
 
Old 11-25-2012, 03:51 AM   #3
1300
Member
 
Registered: Nov 2011
Posts: 45

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AwesomeMachine View Post
Grep doesn't solve inequalities. It only performs OR logic.

---------- Post added Nov 25th, 2012 at 02:43 ----------

I think what you want is PERL or awk.
yeah,, I guess awk is doing fine to get the proper info from the command it self

#df -Pm | awk '+$5 >= 90 {print}'

but what if I want to search within the file and starting from the word (example: MOUNTED to FILES). meanwhile, the output in the file is coming from (#df -h) and formatted as following which means that (#df -Pm | awk '+$5 >= 90 {print}') wont work !!

"
MOUNTED DISKS:
=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rootvg-rootlv
41284928 34906148 4281884 90% /
tmpfs 4027764 24 4027740 1% /dev/shm
/dev/sda1 178488 55052 114220 33% /boot
/dev/mapper/rootvg-homelv
3096336 1406444 1532632 48% /home
/dev/mapper/rootvg-varlv
2064208 948300 1011052 49% /var
/dev/mapper/storix_vg-backups_lv
516061624 386783732 103063492 79% /backups
/rhel-server-5.6-x86_64-dvd.iso
3705128 3705128 0 100% /test



FILES SYSTEM TABLE
=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=
"

Last edited by 1300; 11-25-2012 at 09:40 AM.
 
Old 11-25-2012, 04:17 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
To simplify little more, you can use:
Code:
df -h | awk '$5 >=90 {print $5,$6}'
If you first store output of df -h in a file, let's say in file mydf.txt, then try:
Code:
df -h > /home/example/mydf.txt
awk '$5 >=90 {print $5,$6}' /home/example/mydf.txt
OR YOU CAN USE:
awk '$5 >=90 {print $0}' /home/example/mydf.txt

Last edited by shivaa; 11-25-2012 at 04:28 AM.
 
Old 11-25-2012, 09:39 AM   #5
1300
Member
 
Registered: Nov 2011
Posts: 45

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
To simplify little more, you can use:
Code:
df -h | awk '$5 >=90 {print $5,$6}'
If you first store output of df -h in a file, let's say in file mydf.txt, then try:
Code:
df -h > /home/example/mydf.txt
awk '$5 >=90 {print $5,$6}' /home/example/mydf.txt
OR YOU CAN USE:
awk '$5 >=90 {print $0}' /home/example/mydf.txt
#df -Ph | awk '+$5 >=90 {print}'
is working fine for me, but what if I want it to display greater then 90 and null or a MSG saying "NONE" through a script as below :


"
if [ `df -Ph | awk '+$5 >=90 {print}'` != "null" ]; then
echo
echo "NONE"
else
echo "Hostname : `hostname -s`"
echo "Filesystem Size Used Avail Use% Mounted on"
df -Ph | awk '+$5 >=90 {print}'
echo
exit 1
fi
"
 
Old 11-25-2012, 10:36 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
...but what if I want it to display greater then 90 and null or a MSG saying "NONE" through a script as below :
Wait.. What's your ultimate purpose of doing this?
Your script also have lot of problems which need to be fixed, but first let's know what your aim by doing this?
 
Old 11-26-2012, 03:12 AM   #7
1300
Member
 
Registered: Nov 2011
Posts: 45

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Wait.. What's your ultimate purpose of doing this?
Your script also have lot of problems which need to be fixed, but first let's know what your aim by doing this?
Yeah,, it doesn't work. I quoted the script I wrote just to clarify my aim

in this threat I came out with the below, to display filesystems greater than 90% and it works
#df -Ph | awk '+$5 >=90 {print}'

and am trying to include it in a monitoring tool which generates several informational files inside each server then gathering it and tar it to be sent to the host server. however, tracing info from the original generated files are a bit difficult, so am trying to include the resulted command into that monitoring scripts to have a summary of all servers file system utilization condition


till now I added below and it seems working fine but am looking forward to reduce more unnecessary output

"
diskdf()
{

echo "Hostname : `hostname -s`"
echo "Filesystem Size Used Avail Use% Mounted on"
df -Ph | awk '+$5 >=90 {print}'
}

"


and

"
###
### Gather Information
###
build_file()
{
general_p1
network_base
general_p2
chk_config
diskinfo
networkinfo
systeminfo
sockets
software
croninfo
proctable
dmesginfo
diskdf <<<<<<<<<<<<<<<<<<<<<< my edit
}

###
### GATHER AND GENERATE PAGES
###
generate_pages()
{
indexpage > $DPATH/$HST/index.html
menupage > $DPATH/$HST/menu.html
msg="General Info"; display_update
general_p1 > $DPATH/$HST/general.txt
msg="Network Info"; display_update
network_base >> $DPATH/$HST/general.txt
msg="More General Info"; display_update
general_p2 >> $DPATH/$HST/general.txt
msg="Config Info"; display_update
chk_config > $DPATH/$HST/chkconfig.txt
msg="Disk Info"; display_update
diskinfo > $DPATH/$HST/disks.txt
diskdf > $DPATH/$HST/disksdf.txt <<<<<<<<<<<<<< my edit
msg="More Network Info"; display_update
networkinfo > $DPATH/$HST/network.txt
network_base >> $DPATH/$HST/network.txt
msg="System Info"; display_update
systeminfo > $DPATH/$HST/system.txt
msg="Socket Info"; display_update
sockets > $DPATH/$HST/sockets.txt
msg="Software Info"; display_update
software > $DPATH/$HST/software.txt
msg="Cron Info"; display_update
croninfo > $DPATH/$HST/cron.txt
msg="Processor Info"; display_update
proctable > $DPATH/$HST/proc.txt
msg="Dmesg Info"; display_update
dmesginfo > $DPATH/$HST/dmesg.txt

"


in the existing way! I will get no output other than the "echo"s for the servers which don't have a filesystem greater than 90% which I wanted it to be null to avoid unnecessary entries in the general report

Last edited by 1300; 11-26-2012 at 03:14 AM.
 
  


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
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 03:07 PM
grep greater than time period?? nomiezvr4 Programming 52 08-18-2011 12:19 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
80x25 and Greater... SpEcIeS Debian 4 02-07-2005 12:10 PM
No Greater Gift ... moorege LinuxQuestions.org Member Intro 0 08-24-2003 02:02 PM


All times are GMT -5. The time now is 02:53 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