It is currently Tue, 17 May 2022 19:00:21 GMT



 
Author Message
 disk space monitor
How to extract actual free space value out of df output using shell
and sed only? Say on Linux
#df -k  /pt
Filesystem  1k-blocks      Used  Available  Use%  Mounted on
/dev/hda5       202220  121144       70336     63%                    /

I want to assign 202220 to some variable to compare with treshold.

Thanks.



 Tue, 03 Jun 2003 11:10:04 GMT   
 disk space monitor
20220 is not the free space; it's the size of the file system.  If you want to get that
number into a variable, do

    $ N=`df -k /pt | awk 'NR == 2 {print $2}'`

If you want to get the available space, 70336, into a variable do

    $ N=`df -k /pt | awk 'NR == 2 {print $4}'`

---Robert

_______________________________________

 >
 > How to extract actual free space value out of df output using shell
 > and sed only? Say on Linux
 > #df -k  /pt
 > Filesystem  1k-blocks      Used  Available  Use%  Mounted on
 > /dev/hda5       202220  121144       70336     63%                    /
 >
 > I want to assign 202220 to some variable to compare with treshold.
 >
 > Thanks.



 Tue, 03 Jun 2003 12:43:27 GMT   
 disk space monitor

Silly me, of course I meant 70336.

Yes, I know how to do that with awk, but sed is the only
editor awailable on this embedded system. Any way to
get it with bash, sed but without awk?

Pavel.



 Tue, 03 Jun 2003 14:49:55 GMT   
 disk space monitor
    $ set -- $(df -k /pt)
    $ echo ${11}

---Robert

___________________

 >
 > >20220 is not the free space; it's the size of the file system.  If you want
 > to get that
 > >number into a variable, do
 >
 > Silly me, of course I meant 70336.
 >
 > >
 > >    $ N=`df -k /pt | awk 'NR == 2 {print $2}'`
 > >
 >
 > Yes, I know how to do that with awk, but sed is the only
 > editor awailable on this embedded system. Any way to
 > get it with bash, sed but without awk?
 >
 > Pavel.



 Wed, 04 Jun 2003 03:33:18 GMT   
 disk space monitor

Brilliant! Thanks, Robert.



 Thu, 05 Jun 2003 12:06:37 GMT   
 disk space monitor
Is there some reason you can't use awk?  It's a standard utility
and by far the best thing to use here:

myvar=$(df -k /pt | awk '/hda/ {print $2}')

--
                                Chris Mattern



 Sat, 07 Jun 2003 06:33:24 GMT   
 
   [ 6 post ] 

Similar Threads

1. How to monitor disk space usage and performance

2. snmp monitoring disk space ?

3. monitoring disk space?

4. monitoring free disk space

5. Utility to monitor free disk space..

6. Monitoring disk space

7. Out of disk space though df/du show space available

8. Strange disk free space/used space...

9. Accessing LOCAL disk drives? (and Disk Space theory)


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software