
09-27-2002, 08:21 PM
|
|
Corporate Member
|
|
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
|
|
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... 
|

09-28-2002, 10:17 AM
|
|
Junior Guru Wannabe
|
|
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.
|

09-28-2002, 10:54 AM
|
|
Corporate Member
|
|
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
|
|
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 
|

09-28-2002, 12:14 PM
|
|
Web Hosting Master
|
|
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....
|

09-28-2002, 12:47 PM
|
|
Web Hosting Master
|
|
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.
|

09-28-2002, 12:53 PM
|
|
Corporate Member
|
|
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
|
|
working on it now with interactive
We will show you the outcome 
|

09-28-2002, 06:29 PM
|
|
Quant Trader
|
|
Join Date: May 2001
Location: HK
Posts: 2,931
|
|
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!
|

09-29-2002, 01:13 AM
|
|
Web Hosting Master
|
|
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
|

09-29-2002, 05:42 AM
|
|
Corporate Member
|
|
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
|
|
Im here, Im here !!!! bah! 
|

09-29-2002, 12:47 PM
|
|
Corporate Member
|
|
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
|
|
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 ?
|

11-08-2002, 04:11 PM
|
|
Web Hosting Master
|
|
Join Date: Sep 2002
Posts: 3,892
|
|
matt,
you will need to make it suid something important or sgid group all web users are in.
|

11-08-2002, 06:10 PM
|
|
New Member
|
|
Join Date: Nov 2002
Posts: 2
|
|
Quote:
|
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 ~.
|

11-08-2002, 06:13 PM
|
|
New Member
|
|
Join Date: Nov 2002
Posts: 2
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|