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

86 lines
1.8 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 19:03:27 +02:00
#fileoperations
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 19:03:27 +02:00
file = open("/proc/mounts", "r")
mounts = file.read()
file.close()
2012-05-15 11:12:02 +02:00
2012-05-15 19:03:27 +02:00
#definitions
2012-05-15 11:12:02 +02:00
partitions = []
2012-05-15 17:22:05 +02:00
blocks = []
2012-05-15 19:03:27 +02:00
mountpoints = []
# getting all local partitions (regardless if mounted or not)
2012-05-15 17:22:05 +02:00
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":
2012-05-15 19:03:27 +02:00
partitions.append("/dev/" + line.split()[3])
2012-05-15 17:22:05 +02:00
blocks.append(line.split()[2])
2012-05-15 11:12:02 +02:00
2012-05-15 19:03:27 +02:00
hold="nothing"
holdblocks = 0
blockcount = 0
counter = 0
for part in partitions:
if hold in part:
print "part %s contains hold %s" %(part, hold)
blockcount = blockcount + int(blocks[counter])
print blockcount
else:
print "part %s does not contain hold %s" %(part, hold)
hold = part
holdblocks = blocks[counter]
blockcount = 0
counter += 1
2012-05-15 11:12:02 +02:00
2012-05-15 11:31:00 +02:00
exit()
2012-05-15 19:03:27 +02:00
#getting mountpoints to devices
for item in partitions:
for line in mounts.split("\n"):
if line and item in line:
mountpoints.append(line.split()[1])
break
# mountpoints.append("%s not mounted" %(item))
2012-05-15 11:12:02 +02:00
2012-05-15 19:03:27 +02:00
print "partitions: %s\nblocks: %s\nmountpoints: %s" %(partitions, blocks, mountpoints)
exit()
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