#!/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
阅读(5341) | 评论(0) | 转发(0) |