1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #解析标题+多行数据 返回dict对象 def resolving_shell_table_data_line(ckeys,cvalue): """ ckeys= "mountpoint free used" cvalue = " /dev/sda2 9.0G 5% /dev/sda3 4.5G 4% /dev/sda7 18G 50%" return [ {‘mountpoint‘:‘/dev/sda2‘,‘free‘:‘9.0G‘,‘used‘:‘5%‘}, {‘mountpoint‘:‘/dev/sda3‘,‘free‘:‘4.5G‘,‘used‘:‘4%‘}, {‘mountpoint‘:‘/dev/sda7‘,‘free‘:‘18G‘,‘used‘:‘50%‘}, ] """ keys = [i for i in ckeys.replace( "\n" ," ").split(" ") if i!=" "] res = [] for p in cvalue: p1 = [i for i in p.replace( "\n" ," ").split(" ") if i!=" "] if len (p1)! = len (keys): log( "error data " ) log(cvalue) log(keys) else : res.append( dict ( zip (keys,p1))) return res |
1 | string.atof(item[ ‘used‘ ].replace( "%" ,"")) |
python-门户应用状态检查脚本,布布扣,bubuko.com
原文:http://www.cnblogs.com/zhangbo2012/p/c64a557fd23ea0a303caf2e0eaf4acec.html