Chinaunix首页 | 论坛 | 博客
  • 博客访问: 236500
  • 博文数量: 27
  • 博客积分: 832
  • 博客等级: 准尉
  • 技术积分: 336
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-20 20:47
文章存档

2012年(9)

2010年(10)

2009年(7)

2008年(1)

我的朋友

分类: Python/Ruby

2012-04-06 10:39:16

#!/usr/bin/python
#filename diskstatus.py
#The script file output the total disk space and has been used space
import string
import commands
#Filesystem Diskspace Used Available Use% Mounted on
#/dev/mapper 6856200 5921240 581068 92% /
#/dev/sda1 194442 12378 172025 7% /boot
#tmpfs 517472 0 517472 0% /dev/shm

dfCommand = 'df | sed "1d"'#1d is remove the first row
dfStatus, dfOutput = commands.getstatusoutput(dfCommand)
dfArr = dfOutput.split()

dfOutputCol = 6
FilesystemNum = len(dfArr)/dfOutputCol
DiskSpace = 0
DiskUsedSpace = 0
DiskSpaceCol = 1
DiskUsedSpaceCol = 2

for i in range(0, FilesystemNum):
    DiskSpace += string.atoi(dfArr[i * dfOutputCol + DiskSpaceCol])
    DiskUsedSpace += string.atoi(dfArr[i * dfOutputCol + DiskUsedSpaceCol])

Output = """

   
        1
        %d
        %d
   

""" %(DiskSpace,DiskUsedSpace)

print Output
阅读(5284) | 评论(0) | 转发(0) |
0

上一篇:dhcp client 配置

下一篇:没有了

给主人留下些什么吧!~~