Grab the return value of df -H-m


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grab the return value of df -H-m
# 1  
Old 11-19-2012
Tools Grab the return value of df -H-m

Hi to everyone Smilie

Quick question how do i grab the return value on the 5 position here :


Code:
sgs@sibs:~$ df -H -m
Sist.fichs     1M-blocos  Used    Available  Use%    Mounted on
/dev/sda1    35542         18904   14833       57%            /


In this case the Use% value .

I need to make like if [ Use eq 99% ] then bla bla bla bla . fi Smilie

tnx in advance

Last edited by joeyg; 11-19-2012 at 10:33 AM.. Reason: corrected spelling
# 2  
Old 11-19-2012
Code:
df -H -m | awk '$5 == "99%"{print "Bla bla"}'

# 3  
Old 11-19-2012
tnx for ur fast response do you know if is possible to get only the value from the Use percentage % Like if i got 99% of the disk used i will get a output of 99 only as a output from the command or if i have 70% of the disk being used i will get only 70 as a return value ?
# 4  
Old 11-19-2012
For a shell test you need to have one single item to compare to. If you have multiple file systems, you need to select one only for the test, as well as eliminate the header. On top, the percent sign will interfere with further calculations, thus should be eliminated as well. So you might want to try sth. like (working on linux/bash):
Code:
 [ "99" -eq $(df -h -m|awk '/sda1/{sub("%","",$5); print $5}') ] && echo "good" || echo "bad"

If you don't reduce the query to one item, you'll get sth. like
Code:
bash: [: too many arguments


Last edited by RudiC; 11-19-2012 at 08:15 AM.. Reason: Integer comparison (-eq or -gt/-lt) needed for numbers; string comp (<=, ==, <=) for strings
# 5  
Old 11-19-2012
hmmm i see i was doing this while i was asking to have a ideia how to do it my way was

Code:
df -H -m | awk '{print $4}' >  exemplo.txt 


if [ ´ cat exemplo.txt | grep -c 99 ´ = 1 ] 
then
   rm bla.zip
fi

# 6  
Old 11-19-2012
Your code has many improvement opportunities; e.g. use $5 instead of $4; the grep will also find numbers like 109920 (OK, not in col 5!), and, you can do all that in a one liner.
Give my proposal above a shot and post the results. btw - waiting until a disk is filled to 99% before counteracting may be too late ...
# 7  
Old 11-19-2012
@Rudic we can further reduce this to single awk.

Code:
[[ $(df -H -m | awk '$5 == "99%"') ]] && rm bla.zip

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

2. Shell Programming and Scripting

Grab fields without awk

so i want to avoid external calls in my script, so im trying to do the following: AllMyLogs="hello---nallo---wello---bollo tello---zello---jello---kello" OLDIFS="$IFS\\\n" IFS="---" set -- ${AllMyLogs} IFS="$OLDIFS" I want it to work in a way that, when i type this: echo $2 I... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Grab contents between two patterns

Hi, What is the best approach to grab contents between Changes Dependencies from the following example snippy Changes in packages about to be updated: bash-3.2-32.el5_9.1.x86_64 * Thu Jun 27 22:00:00 2013 Roman Rakus <rrakus@redhat.com> - 3.2-32.1 - Fixed a bug that caused... (2 Replies)
Discussion started by: ashokvpp
2 Replies

4. Shell Programming and Scripting

Grab the data

Hello Honourable Members, I stuck into one issue, my server is migrating from UNIX to linux and ptree command does not work there. I was working with pstree command in linux and need some help regarding the same. suppose i have one line for example: ram (121)--- sita... (3 Replies)
Discussion started by: singhabm
3 Replies

5. Shell Programming and Scripting

Grab from the file in one command

Dear All, I have a file in which there are 54 fields, i want to grab the all the lines and send to a new file where filed18 has lenght greater than 14. How can i do it without if condition and faster way: currently i am reading file line by line and comparing the length read fileLine... (9 Replies)
Discussion started by: bilalghazi
9 Replies

6. OS X (Apple)

Video grab using ffmpeg?

Does anyone know how to grab video (screen) on Terminal using ffmpeg (not X11). I have written a unix library and I'd like to make a short movie (demo) of it. Tried: I already own SNapz Pro2 but it hangs the system (I have an old Powerbook 15" PPC). I guess my system is too slow for version... (0 Replies)
Discussion started by: sentinel
0 Replies

7. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

8. Shell Programming and Scripting

Grab a smaller and larger value

Hi All, I am trying to grab a term which is just smaller and larger than the assigned value using the below code. But there seems to be some problem. The value i assign is 25 so i would expect it to output a smaller value to be 20 instead of 10 and 20 and larger value to be 30 instead of 30 and... (3 Replies)
Discussion started by: Raynon
3 Replies

9. Shell Programming and Scripting

grab the line using awk

suppose u have a file AAAAAKKSKSKMSKMSKBNNSHNKSNJNMSYNMSBH This is exactly wht the input is like Question is i want to list wht is on the line 5 tht will be A but Remember u want to extract in between say from 100 to 300 i tried using awk 'BEGIN {FS=""} {print$100,$300}' file but it will... (1 Reply)
Discussion started by: cdfd123
1 Replies

10. Shell Programming and Scripting

How to grab data between 2 strings ?

Hi All, I have a text file below. How do i grab all the data between "05T00NPQSMR1" and "****" using awk ? Pls note that the text lines may not be fixed and text content is dynamic. Pls help. Thanks Below is my code where $LOT_SUFFIX is my shell variable. awk '/'"$LOT_SUFFIX"'/,/blah/'... (16 Replies)
Discussion started by: Raynon
16 Replies
Login or Register to Ask a Question