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

45 lines
1.0 KiB
Python
Raw Normal View History

2012-05-14 00:13:50 +02:00
#!/usr/bin/python2.7
2012-05-15 11:31:00 +02:00
import os
2012-05-15 11:12:02 +02:00
file = open("/proc/partitions", "r")
file = file.read()
# getting all local partitions (regardless if mounted or not)
partitions = []
for line in file.split("\n"):
2012-05-15 11:31:00 +02:00
#if "sd" in line or "hd" in line:
#if line.split()[3] != None or line.split()[3] != "name":
if line and "name" not in line and "sr0" not in line:
2012-05-15 11:12:02 +02:00
partitions.append(line.split()[3])
print "partitions on this system: %s" %(partitions)
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