Can there be a better option?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can there be a better option?
# 1  
Old 12-18-2009
Question Can there be a better option?

Hello,

I am still in the process of learning Shell Programming. The online manual, that I am referring to had following question:

Quote:
Write a script to test whether the free disk space on your largest partition is less than 10%. If it is, print a message to the screen indicating this fact.
I made a script as follows:

Code:
df --block-size=1GB | tr -s ' '| cut -d' ' -f2,5 | grep -v 1GB* | sort -k1,2n | tail -1 | cut -d' ' -f2 | cut -d '%' -f1

and it gave me correct result of the free space (in % without the % sign) on my machine's largest partition.

But I am sure that there exists a better and probably shorter script than the one made by me. Can someone provide such a script?

Thanks.
# 2  
Old 12-18-2009
Code:
df | gawk 'NR>1 && $5+0<=10'


Last edited by ichigo; 12-18-2009 at 03:07 AM..
# 3  
Old 12-18-2009
Question

Quote:
Originally Posted by ichigo
Code:
df | gawk 'NR>1 && $5+0<=10'

I've not reached upto gawk yet.

Moreover the script given by you shows just the tmpfs in my machine.. And it's not the largest partition in my system.. It's 975MB in size. And there's no other figure there that's greater than 975. I mean there's a partition that's of 60GB but 60 < 975. That's how it's working, I guess..

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Unrecognized option: sparc-sun-Solaris2.10/bin/as: unrecognized option `-m32'

Hi, I installed some packages required by an app built with python. But when I try python setup.py install, I get the following error: /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/../../../../sparc-sun-solaris2.10/bin/as: unrecognized option `-m32' Could anyone tell me what's wrong... (4 Replies)
Discussion started by: Kimkun
4 Replies

2. Shell Programming and Scripting

-f option and -rf in rm

Hi, I'm new to shell scripting and I'm trying to read some code I need to use. Could you help me out on what it's doing? I read this as.... if the directory has files then rm all the files in that directory. I'm not sure.... if ; then run "rm -rf ${TSP_FILEPATH_PLUGIN_DIR}"; fi run... (8 Replies)
Discussion started by: jdilts
8 Replies

3. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

4. Programming

g++ and the -R option

hi everybody, can somebody tell me what -R option on g++ on solaris means : g++ -DAIX -fpic -static -o printps printps.o -L/epost2/blitz/xercesc1_1 /lib -L/oracle/OraHome/lib32/ L/epost2/blitz/lib -lxerces-c1_1 -lhmltods -lhmlt ops -lgeneric -lnotify -lutil -lclntsh `cat... (0 Replies)
Discussion started by: eternalflame
0 Replies

5. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

6. Shell Programming and Scripting

which is best searching option

Hi, I need one help for choosing best option among sed, perl and awk. I need to search and replace thousand files for a text and need to replace it. I am in confusion for choosing the option for best results. Because by using sed option its taking too much time for searching and replacing... (3 Replies)
Discussion started by: dbsurf
3 Replies

7. UNIX for Dummies Questions & Answers

cp - no to all option?

Hi, Is there a no to all option when copying a bunch of files? instead of pressing enter endlessly. Thanks (6 Replies)
Discussion started by: td_kuoj3
6 Replies

8. Programming

cc option

my yacc output file y.tab.c is not compiling using cc y.tab.c -ly command .possibily option flag -ly is not correct.i m using red hat linux 9.please give solutions. (4 Replies)
Discussion started by: kuldeep_bora
4 Replies

9. UNIX for Advanced & Expert Users

su option

We have started to us the su option on our production server. We log in with our own id and then su into a special id to perform various tasks. This allows our actions to be monitored. I need to know how to use the su option when doing an ftp between two servers. I noticed that when I log into... (1 Reply)
Discussion started by: lesstjm
1 Replies

10. UNIX for Advanced & Expert Users

-h option

Hi what does the following mean in shell scripts (-h option) val contains a string. while (-h "$val") (1 Reply)
Discussion started by: Raom
1 Replies
Login or Register to Ask a Question