November 5th, 2004, 08:08 AM
Help, I need to figure out how to check disk space
I need to write a python script that will check to see if there is more than 50% of available space in the /var directory of my linux operating system. Then I need to check how much space is used on the /var/www/html/da directory.
Right now I was thinking about using the os module and using statvfs.
diskSpace = os.statvfs("/")
But, I don't know how to grab the information that I need or how to use this function.
November 5th, 2004, 01:26 PM
Return the size, in bytes, of path. Raise os.error if the file does not exist or is inaccessible. New in version 1.5.2.
-- that could check the size of the directory (or worst case scenario recusively check the size of all child files)
As for determining free disk space I have no idea
November 5th, 2004, 02:48 PM
Thank you for your suggestion.
I have had a rough time finding how to get the available disk space. At the command line you can use 'df ' but this does not single out the available space.
November 8th, 2004, 07:44 AM
If you use os commands you could do the following
df <dirname> | bash sizeParse.sh
where sizeParse.sh is the following
it's not really a 'python' solution, but it would return the desired information
read i # parse out 'titles'
read i # get line we want
# add string manipulation here to isolate Available space