I'm trying to get the available disk space on a remote linux host using python. The best way I could think to do this would be to os.popen a df command, and use regex to get the available space from the output. I then need to apply a variable to that free space number, which is where I'm stuck.
The output looks like:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 1073409200 321713576 698008536 32% /mnt/test
Here's what I have so far, and what's gotten me the furthest:
import os
import re
PLINK = "C:\\plink.exe -pw password root@"
command = os.popen(PLINK + "hostname" + " df /mnt/test")
output = command.read()
pattern = re.compile('\s\d+\s')
found = pattern.search(output)
now if I do
print found.group(0)
It returns the number of 1k blocks. I cant find a group number that returns the available space. In my rx toolkit that regex matches the 1K blocks and the available space.