#!/usr/bin/python
def cmd_free():
out = commands.getstatusoutput('free')
stat = out[0]
out = out[1].strip().split('\n')
out = str(out[1])
out = re.sub('[ ]{2,}', ' ', out).split(' ')
return {'total':out[1], 'used':out[2], 'free':out[3], 'shared':out[4],'buffers':out[5], 'cached':out[6]}
def cmd_free2():
out = commands.getstatusoutput('''free -m |grep cache:|awk '{print $3" "$4}' ''')
return out[1].split(' ')
if __name__ == '__main__':
import commands
import re
#使用python处理结果
out = cmd_free()
print out
#使用shell 命令处理结果
out2 = cmd_free2()
print out2
阅读(2950) | 评论(1) | 转发(0) |