Reputation: 69
I am running a python script to get few commands to get executed on a remote aix server. The command is to get the size of a file system.
command : df -g | grep -w /
output :
/dev/hd4 0.94 0.87 8% 3865 2% /
I only want 0.87 as output which is the third column of output. I want to extract the value in a variable but grep will give me a scalar value. Please let me know how can I format this command to do what i intend to do.
Upvotes: 1
Views: 214
Reputation: 5660
You can use subprocess.check_output
with shell=True
:
import subprocess
print(subprocess.check_output(["df -g | grep -w /"], shell=True).split()[2])
.split()
splits the return into the separate values, and then [2]
gets the value that you want.
Upvotes: 1