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

93 lines
2.0 KiB
Python
Executable File

#!/usr/bin/python2
import os
#fileoperations
file = open("/proc/partitions", "r")
parts = file.read()
file.close()
file = open("/proc/mounts", "r")
mounts = file.read()
file.close()
#definitions
partitions = []
blocks = []
mountpoints = []
# getting all local partitions (regardless if mounted or not)
for line in parts.split("\n"):
if line and "name" not in line and "sr0" not in line:
if line.split()[2] != "1":
partitions.append("/dev/" + line.split()[3])
blocks.append(line.split()[2])
hold="nothing"
holdblocks = 0
blockcount = 0
counter = 0
partsnew = []
blocksnew = []
for part in partitions:
if hold in part:
print "part %s contains hold %s" %(part, hold)
blockcount = blockcount + int(blocks[counter])
print blockcount
partsnew.append(part)
blocksnew.append(blocks[counter])
else:
print "part %s does not contain hold %s" %(part, hold)
hold = part
holdblocks = blocks[counter]
blockcount = 0
counter += 1
partitions = partsnew
blocks = blocksnew
#getting mountpoints to devices
counter = 0
for item in partitions:
for line in mounts.split("\n"):
if line and item in line:
mountpoints.append(line.split()[1])
if line.split()[1] not in mountpoints[counter]:
mountpoints.append("%s not mounted" %(item))
counter += 1
print "partitions: %s\nblocks: %s\nmountpoints: %s" %(partitions, blocks, mountpoints)
exit()
# given paths(mountpoints)
path=("/boot", "/", "/dev/sda6")
#output head
print "mountpoints\tfree megabytes"
print "------------------------------"
#work path tuple
for mountpoint in path:
#check if given path is a mountpoint
# if os.path.ismount(mountpoint):
#create statvfs object
fs = os.statvfs(mountpoint)
#calculate free megabytes
freembytes = fs.f_bavail * fs.f_bsize / 1024**2.0
#output
print "%s\t\t%.1f MB" %(mountpoint, freembytes)
# else:
# print "error: given path is not a mountpoint"
# end of file