Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037

    another simple script needed

    Ok, im looking to make a simple report page for disk usage per user.

    I setup my server so each customer has a home dir /home/webhost/username/..

    So i need a php script which runs the "du" command for each dir within /home/webhost/ and produces a nice page with Username and disk usage summaraised for each user within the webhost dir.

    Im quite new to PHP and i know this is simple.. i just cant get the output working right... any guru want to shed some light on this...
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  2. #2
    Join Date
    Sep 2002
    Posts
    44
    Sorry but no help, but for anyone that reads this you can execute shell commands with the backquotes, e.g `du` but that would only work for the current directory.

  3. #3
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037
    yeah.. i tried passing a variable from a text box to the command and things like that...

    I need php to grab all the usernames from the dir, run the command.. sort the output and create some html
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  4. #4
    Join Date
    Aug 2002
    Location
    Chandler, Arizona
    Posts
    2,564
    what you would do is open the directory (like the base directory where all the site folders are) run aloop and do du for each....im not much of a linux guru so bear that in mind....you can run command line by going like exec("commands blah blah");

    iv been messing with php for years not and i cant figure out like how to get all of waht exec returns...like i can get the last line but thats it....
    -Robert Norton
    www.SophMedia.com

  5. #5
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    What I would probably do is loop through the directory (ignoring . and ..) and get the file size using the PHP built in file size function.

  6. #6
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037
    working on it now with interactive

    We will show you the outcome
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  7. #7
    Join Date
    May 2001
    Location
    HK
    Posts
    3,076

    Smile

    Code:
    #!/usr/bin/perl
    use strict;
    
    my $base_dir = q(/home/webhost);
    
    chdir($base_dir) or die print "Fail CHDIR: $!\n";
    
    foreach (<*>) {
    		chomp;
    		print qx(du -s $base_dir/$_);
    }
    
    __END__

    Run it in SSH.
    It works for me... um cuz I wrote it!

  8. #8
    Join Date
    Aug 2002
    Location
    Chandler, Arizona
    Posts
    2,564
    ugg lol i got it course matt is in the uk...so hes not there :'( matt
    -Robert Norton
    www.SophMedia.com

  9. #9
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037
    Im here, Im here !!!! bah!
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  10. #10
    Join Date
    Aug 2002
    Location
    London, UK
    Posts
    9,037
    I got interactives great script working now we have another problem.

    The DU command cannot be run in each users home dir by the user "nobody" (apache) because of permission problems. How do i get around this ?

    Can i grant the use of DU anywhere by a user or osmething ?
    Matt Wallis
    United Communications Limited
    High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
    UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

  11. #11
    matt,

    you will need to make it suid something important or sgid group all web users are in.
    * Rusko Enterprises LLC - Upgrade to 100% uptime today!
    * Premium NYC collocation and custom dedicated servers
    call 1-877-MY-RUSKO or paul [at] rusko.us

    dedicated servers, collocation, load balanced and high availability clusters

  12. #12

    backticks

    iv been messing with php for years not and i cant figure out like how to get all of waht exec returns...like i can get the last line but thats it....
    Use backticks instead of system or exec if you want the output of the command.

    $var = `du -sh /tmp`;

    The backtick is generally to the left of your 1 key. It's on the same key as the ~.

  13. #13
    Also, you're definitely gonna run into permissions problems with this script since you can't use du on directories that you don't have read permission on.

    I recommend running this as a cron job every so often and storing the info in a database or flat file instead of letting users slam your filesystem by running a du all the time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •