Retrieving a specific value from "df -h" using shell
- by Diego Dias
When I use df -h, I get the following output:
Filesystem Size Used Avail
Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
59G 2.2G 54G 4% /
/dev/sda1 122M 38M 78M
33% /boot
tmpfs 1.1G 0 1.1G
0% /dev/shm
10.10.0.105:/somepath
11T 8.4T 2.1T 81% /storage4
10.11.0.101:/somepath
15T 8.9T 5.9T 61% /storage1
/dev/mapper/patha 5.0T 255G 4.8T
5% /storage5_vol0
/dev/mapper/pathb 5.0T 195G 4.9T
4% /storage5_vol1
/dev/mapper/pathc 5.0T 608G 4.5T
12% /storage5_vol2
I want to write a script that gets the value of Avail column on a specific storage.
I used to use
df -k /storage_name | tail -1 | awk
'{print $3}'
But the FileSystem column can have a value or not .. which would change the variable of my script from $3 to $4.
How can I get the Avail on a single command line even if there are no values on the previous columns?