Hello,
I'm new to Python and using 3.6 for this code. I wrote the code below to report on a Linux filesystem called '/u01'. What I'd like to do is loop through the absolute filesystems and print out the size, free space, etc for each of the filesystems such as '/','/backup','/var', etc.
Here is my current piece of code:
Appreciate the help!
Frank
I'm new to Python and using 3.6 for this code. I wrote the code below to report on a Linux filesystem called '/u01'. What I'd like to do is loop through the absolute filesystems and print out the size, free space, etc for each of the filesystems such as '/','/backup','/var', etc.
Here is my current piece of code:
import subprocess import os, sys from collections import namedtuple def get_path_usage(path): space_st = os.statvfs(path) # f_bavail: without blocks reserved for super users # f_bfree: with blocks reserved for super users avail = space_st.f_frsize * space_st.f_bavail capa = space_st.f_frsize * space_st.f_blocks used = round((capa - avail) / 1024 / 1024) percent = float(used) / capa # print using str.format(python 3) method for variables print ("Path: {}".format(path)) print ("Total: {}".format(capa)) print ("Used: {}".format(used)) print ("Available: {}".format(avail)) print ("Percent: {}".format(percent)) x = get_path_usage('/u01') print (x)I'd like to know how to add another function to loop through directories, or even add the directories to a list, to report on their size. I've been looking around for a while and decided to ask the experts with this post.
Appreciate the help!
Frank