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

47 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/python2
2012-05-14 00:13:50 +02:00
2012-05-15 11:31:00 +02:00
import os
2012-05-15 11:12:02 +02:00
file = open("/proc/partitions", "r")
2012-05-15 17:22:05 +02:00
parts = file.read()
file.close()
2012-05-15 11:12:02 +02:00
# getting all local partitions (regardless if mounted or not)
partitions = []
2012-05-15 17:22:05 +02:00
blocks = []
for line in parts.split("\n"):
2012-05-15 11:31:00 +02:00
if line and "name" not in line and "sr0" not in line:
2012-05-15 17:22:05 +02:00
if line.split()[2] != "1":
partitions.append(line.split()[3])
blocks.append(line.split()[2])
2012-05-15 11:12:02 +02:00
2012-05-15 17:22:05 +02:00
print "partitions: %s \nblocks: %s" %(partitions, blocks)
2012-05-15 11:12:02 +02:00
2012-05-15 11:31:00 +02:00
exit()
2012-05-15 11:12:02 +02:00
2012-05-14 00:13:50 +02:00
2012-05-14 11:27:28 +02:00
# given paths(mountpoints)
2012-05-15 11:31:00 +02:00
path=("/boot", "/", "/dev/sda6")
2012-05-14 00:13:50 +02:00
2012-05-14 11:27:28 +02:00
#output head
2012-05-15 11:31:00 +02:00
print "mountpoints\tfree megabytes"
print "------------------------------"
2012-05-14 11:27:28 +02:00
#work path tuple
2012-05-15 11:31:00 +02:00
for mountpoint in path:
2012-05-14 11:27:28 +02:00
#check if given path is a mountpoint
2012-05-15 11:12:02 +02:00
# if os.path.ismount(mountpoint):
2012-05-14 11:27:28 +02:00
#create statvfs object
2012-05-15 11:31:00 +02:00
fs = os.statvfs(mountpoint)
2012-05-14 11:27:28 +02:00
#calculate free megabytes
2012-05-15 11:31:00 +02:00
freembytes = fs.f_bavail * fs.f_bsize / 1024**2.0
2012-05-14 11:27:28 +02:00
#output
2012-05-15 11:31:00 +02:00
print "%s\t\t%.1f MB" %(mountpoint, freembytes)
2012-05-15 11:12:02 +02:00
# else:
# print "error: given path is not a mountpoint"
2012-05-14 00:13:50 +02:00
# end of file