#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    180
    Rep Power
    11

    Unhappy 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.

    import os
    diskSpace = os.statvfs("/")

    But, I don't know how to grab the information that I need or how to use this function.

    Any Suggestions?

    Thank You.
  2. #2
  3. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,400
    Rep Power
    1233
    os.getsize( path)
    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)

    Referencehttp://docs.python.org/lib/module-os.path.html

    As for determining free disk space I have no idea

    -MBirchmeier
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    180
    Rep Power
    11
    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.

    Thanks Again

    -Laura
  6. #4
  7. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,400
    Rep Power
    1233
    If you use os commands you could do the following

    df <dirname> | bash sizeParse.sh

    where sizeParse.sh is the following
    Code:
    read i # parse out 'titles'
    read i # get line we want
    
    # add string manipulation here to isolate Available space
    echo $i
    it's not really a 'python' solution, but it would return the desired information

    -MBirchmeier

IMN logo majestic logo threadwatch logo seochat tools logo