socialnerds/hive
socialnerds
/
hive
Archived
1
0
Fork 0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
hive/df_check.py

27 lines
609 B
Python
Raw Normal View History

2012-05-14 00:13:50 +02:00
#!/usr/bin/python2.7
import os
2012-05-14 11:27:28 +02:00
# given paths(mountpoints)
2012-05-14 00:13:50 +02:00
path=("/boot", "/", "/home/")
2012-05-14 11:27:28 +02:00
#output head
2012-05-14 00:13:50 +02:00
print "mountpoints\tfree megabytes"
print "------------------------------"
2012-05-14 11:27:28 +02:00
#work path tuple
2012-05-14 00:13:50 +02:00
for mountpoint in path:
2012-05-14 11:27:28 +02:00
#check if given path is a mountpoint
2012-05-14 00:13:50 +02:00
if os.path.ismount(mountpoint):
2012-05-14 11:27:28 +02:00
#create statvfs object
2012-05-14 00:13:50 +02:00
fs = os.statvfs(mountpoint)
2012-05-14 11:27:28 +02:00
#calculate free megabytes
2012-05-14 00:13:50 +02:00
freembytes = fs.f_bavail * fs.f_bsize / 1024**2.0
2012-05-14 11:27:28 +02:00
#output
2012-05-14 00:13:50 +02:00
print "%s\t\t%.1f MB" %(mountpoint, freembytes)
else:
print "error: given path is not a mountpoint"
# end of file