Project

General

Profile

« Previous | Next » 

Revision ff7733eb

Added by David Sorber over 10 years ago

Fixing a minor issue I found where "df -h <device file>" no longer returns the information for the specified device file. Instead it seems to return udev for /dev/sda1. Anyway, I fixed the issue by piping the output of df to grep.

View differences:

software/misc/display.py
END = '\033[0m'
def make_bold(string):
return '{:s}{:s}{:s}'.format(BOLD, string, END)
return '{:s}{:s}{:s}'.format(BOLD, string, END)
def get_ipv4_addr(interface):
cmd = 'ifconfig {:s}'.format(interface)
for line in subprocess.check_output(cmd, shell=True).split('\n'):
if line.strip().startswith('inet addr:'):
return line.split()[1][5:]
else:
return '{:s}NO IP ASSIGNED{:s}'.format(RED, END)
cmd = 'ifconfig {:s}'.format(interface)
for line in subprocess.check_output(cmd, shell=True).split('\n'):
if line.strip().startswith('inet addr:'):
return line.split()[1][5:]
else:
return '{:s}NO IP ASSIGNED{:s}'.format(RED, END)
def get_fs_usage(mount_point):
cmd = 'df -h {:s}'.format(mount_point)
try:
line = subprocess.check_output(cmd, shell=True).split('\n')[1]
except IndexError:
return '{:s}MOUNT POINT NOT FOUND{:s}'.format(RED, END)
line_tokens = line.split()
output = '{:10s} ({:<9s}) - {:>4s} of {:>4s} [ {:s} ] used; '\
'{:>4s} available'.format(line_tokens[5], line_tokens[0],
line_tokens[2], line_tokens[1],
line_tokens[4], line_tokens[3])
return output
cmd = 'df -h | grep {:s}'.format(mount_point)
try:
line = subprocess.check_output(cmd, shell=True).split('\n')[0]
except IndexError:
return '{:s}MOUNT POINT NOT FOUND{:s}'.format(RED, END)
line_tokens = line.split()
output = '{:10s} ({:<9s}) - {:>4s} of {:>4s} [ {:s} ] used; '\
'{:>4s} available'.format(line_tokens[5], line_tokens[0],
line_tokens[2], line_tokens[1],
line_tokens[4], line_tokens[3])
return output
def main():
""" This is a custom script I wrote to run on at login on phalanx
and give me some system overview information.
"""
""" This is a custom script I wrote to run on at login on phalanx
and give me some system overview information.
"""
rows, columns = os.popen('stty size', 'r').read().split()
rows = int(rows)
columns = int(columns)
rows, columns = os.popen('stty size', 'r').read().split()
rows = int(rows)
columns = int(columns)
hostname = subprocess.check_output('hostname', shell=True).strip()
hostname = subprocess.check_output('hostname', shell=True).strip()
ip_addr = get_ipv4_addr('p1p1')
root_stats = get_fs_usage('/dev/sda1')
storage_stats = get_fs_usage('/dev/md0')
ip_addr = get_ipv4_addr('p1p1')
root_stats = get_fs_usage('/dev/sda1')
storage_stats = get_fs_usage('/dev/md0')
print ' _ _ '
print ' | | | | '
print ' _ __ | |__ __ _| | __ _ _ __ __ __'
print "| '_ \| '_ \ / _` | |/ _` | '_ \\ \/ /"
print '| |_) | | | | (_| | | (_| | | | |> < '
print "| .__/|_| |_|\__,_|_|\__,_|_| |_/_/\_\ "
print '| | '
print '|_| '
print '-' * columns
print '{:<16s} {:s} {:s} {:s}'.format(make_bold('Hostname:'), hostname,
make_bold('IP:'), ip_addr)
print '{:<16s} {:s}'.format(make_bold('Storage:'), root_stats)
print '{:<16s} {:s}'.format(make_bold(' '), storage_stats)
print ' _ _ '
print ' | | | | '
print ' _ __ | |__ __ _| | __ _ _ __ __ __'
print "| '_ \| '_ \ / _` | |/ _` | '_ \\ \/ /"
print '| |_) | | | | (_| | | (_| | | | |> < '
print "| .__/|_| |_|\__,_|_|\__,_|_| |_/_/\_\ "
print '| | '
print '|_| '
print '-' * columns
print '{:<17s} {:s} {:s} {:s}'.format(make_bold('Hostname:'), hostname,
make_bold('IP:'), ip_addr)
print '{:<17s} {:s}'.format(make_bold('Storage:'), root_stats)
print '{:<17s} {:s}'.format(make_bold(' '), storage_stats)
print '-' * columns
print subprocess.check_output('w -i', shell=True)
print
print '-' * columns
print subprocess.check_output('w -i', shell=True)
print
if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

Also available in: Unified diff