Page 1 of 1

Getting Disk usage

Posted: Mon Apr 18, 2016 5:59 am
by philspitler
I want to get the disk usage stats from an SMB share.

I can do it in Unix using the following command.

Code: Select all

df -P -t cifs  | awk '{print $5}'
And I have found some Python that works for local disks but when i change the os.statvfs to be my share I get an error.

OSError: [Errno 2] No such file or directory: '//192.168.1.45/Two_Terror/'

It must be something to do with how I am referencing it as a disk... Any ideas?

Chees.

Code: Select all

#!/usr/bin/python
import os
disk = os.statvfs("//192.168.1.45/Two_Terror/")
totalBytes = float(disk.f_bsize*disk.f_blocks)
print "total space: %d Bytes = %.2f KBytes = %.2f MBytes = %.2f GBytes" % (totalBytes, totalBytes/1024, totalBytes/1024/1024, totalBytes/1024/1024/1024)
totalUsedSpace = float(disk.f_bsize*(disk.f_blocks-disk.f_bfree))
print "used space: %d Bytes = %.2f KBytes = %.2f MBytes = %.2f GBytes" % (totalUsedSpace, totalUsedSpace/1024, totalUsedSpace/1024/1024, totalUsedSpace/1024/1024/1024)
totalAvailSpace = float(disk.f_bsize*disk.f_bfree)
print "available space: %d Bytes = %.2f KBytes = %.2f MBytes = %.2f GBytes" % (totalAvailSpace, totalAvailSpace/1024, totalAvailSpace/1024/1024, totalAvailSpace/1024/1024/1024)
totalAvailSpaceNonRoot = float(disk.f_bsize*disk.f_bavail)
print "available space for non-super user: %d Bytes = %.2f KBytes = %.2f MBytes = %.2f GBytes " % (totalAvailSpaceNonRoot, totalAvailSpaceNonRoot/1024, totalAvailSpaceNonRoot/1024/1024, totalAvailSpaceNonRoot/1024/1024/1024) 

Re: Getting Disk usage

Posted: Wed Sep 14, 2016 2:48 am
by bizzle239