tags:

views:

48

answers:

1

I need to build a script that will query a remote storage server with multiple drives for their free space.

I simply login with SSH, run df and throw the output into a variable. Which looks like this:

    Array
(
    [0] => Filesystem           1K-blocks      Used Available Use% Mounted on
    [1] => /dev/sda1             59392320  14949240  41426064  27% /
    [2] => /dev/sdd1            140592240 114503840  18946708  86% /home/overflow
    [3] => /dev/sdf1            287826944 273844324         0 100% /home/node2
    [4] => /dev/sde1            287826944 253278964  19927228  93% /home/node3
    [5] => /dev/sdg1            287826944   4771768 268434424   2% /home/node4
    [6] => /dev/sdh1            287826944   4329780 268876412   2% /home/node5
    [7] => /dev/sdi1            488302976 439077756  24420864  95% /home/node1
    [8] => /dev/sdh1            287826944   4329780 268876412   2% /home/mnode6
    [9] => /dev/sdh1            287826944   4329780 268876412   2% /home/mnode7
    [10] => tmpfs                  3145728         0   3145728   0% /tmp
)

I need to extract how much free space each "node" or "mnode" has. So perhaps a nice array that has pairs such as this:

mnode1 => 24000000
node1 => 24000000
node2 => 0
node3 => 20000000
+2  A: 

Use explode(' ', preg_replace('/ +/', ' ', $line)) to get an array with all values split up.

cweiske