LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep df -h to get greater than 90% (https://www.linuxquestions.org/questions/linux-newbie-8/grep-df-h-to-get-greater-than-90-a-4175438600/)

1300 11-25-2012 01:35 AM

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 !!

AwesomeMachine 11-25-2012 01:42 AM

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.

1300 11-25-2012 02:51 AM

Quote:

Originally Posted by AwesomeMachine (Post 4836408)
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
=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=
"

shivaa 11-25-2012 03:17 AM

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


1300 11-25-2012 08:39 AM

Quote:

Originally Posted by shivaa (Post 4836441)
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
"

shivaa 11-25-2012 09:36 AM

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?

1300 11-26-2012 02:12 AM

Quote:

Originally Posted by shivaa (Post 4836585)
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


All times are GMT -5. The time now is 02:57 PM.