[ SEA-GHOST MINI SHELL]
#!/usr/bin/env python
from __future__ import division
import os
import time
import sys
import subprocess
import argparse
def get_option():
if len(sys.argv) != 3:
print("Usage: nfs_usage_report.py dc|dc1|dc3|tot used|avai|size")
sys.exit()
elif sys.argv[1] not in ("dc", "dc1", "dc3", "tot"):
print("Usage: nfs_usage_report.py dc|dc1|dc3|tot used|avai|size")
sys.exit()
elif sys.argv[2] not in ("used", "avai", "size"):
print("Usage: nfs_usage_report.py dc|dc1|dc3|tot used|avai|size")
sys.exit()
else:
return sys.argv[1], sys.argv[2]
def get_nfs_mounts():
nfs_mounts = []
for mount in file("/proc/mounts"):
if "nfs" and "/home" in mount:
array = mount.split()[0], mount.split()[1]
nfs_mounts.append(array)
return nfs_mounts
def filesystem_info(dirname):
df = subprocess.Popen(["df", "-k", dirname], stdout=subprocess.PIPE)
output = df.communicate()[0]
device, size, used, available, percent, mountpoint = \
output.split("\n")[1].split()
return device, int(size), int(used), int(available)
if __name__ == '__main__':
option, func = get_option()
tot = {'name': 'total', 'size': 0, 'used': 0, 'avai': 0}
dc1 = {'name': 'dc1', 'size': 0, 'used': 0, 'avai': 0}
dc3 = {'name': 'dc3', 'size': 0, 'used': 0, 'avai': 0}
dc = {'name': 'dc', 'size': 0, 'used': 0, 'avai': 0}
for nfs_mount in get_nfs_mounts():
info = filesystem_info(nfs_mount[1])
if "10.11.0.248" in info[0]:
dc1['size'] += info[1]
dc1['used'] += info[2]
dc1['avai'] += info[3]
elif "10.11.0.238" in info[0]:
dc3['size'] += info[1]
dc3['used'] += info[2]
dc3['avai'] += info[3]
elif "10.21.4.7" in info[0]:
dc['size'] += info[1]
dc['used'] += info[2]
dc['avai'] += info[3]
tot['size'] += info[1]
tot['used'] += info[2]
tot['avai'] += info[3]
if option == "dc":
print dc[func]
if option == "dc1":
print dc1[func]
elif option == "dc3":
print dc3[func]
elif option == "tot":
print tot[func]
SEA-GHOST - SHELL CODING BY SEA-GHOST