hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : another simple script needed
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

another simple script needed

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-27-2002, 08:21 PM
UH-Matt UH-Matt is offline
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...

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

Reply With Quote


Sponsored Links
  #2  
Old 09-28-2002, 10:17 AM
Mr_Predator Mr_Predator is offline
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.

Reply With Quote
  #3  
Old 09-28-2002, 10:54 AM
UH-Matt UH-Matt is offline
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

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

Reply With Quote
Sponsored Links
  #4  
Old 09-28-2002, 12:14 PM
interactive interactive is offline
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....

__________________
-Robert Norton
www.SophMedia.com

Reply With Quote
  #5  
Old 09-28-2002, 12:47 PM
Rich2k Rich2k is offline
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.

Reply With Quote
  #6  
Old 09-28-2002, 12:53 PM
UH-Matt UH-Matt is offline
Corporate Member
 
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
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.

Reply With Quote
  #7  
Old 09-28-2002, 06:29 PM
YUPAPA YUPAPA is offline
Quant Trader
 
Join Date: May 2001
Location: HK
Posts: 2,931
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!

Reply With Quote
  #8  
Old 09-29-2002, 01:13 AM
interactive interactive is offline
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

__________________
-Robert Norton
www.SophMedia.com

Reply With Quote
  #9  
Old 09-29-2002, 05:42 AM
UH-Matt UH-Matt is offline
Corporate Member
 
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
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.

Reply With Quote
  #10  
Old 09-29-2002, 12:47 PM
UH-Matt UH-Matt is offline
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 ?

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

Reply With Quote
  #11  
Old 11-08-2002, 04:11 PM
rusko rusko is offline
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.

__________________
* 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

Reply With Quote
  #12  
Old 11-08-2002, 06:10 PM
stoic stoic is offline
New Member
 
Join Date: Nov 2002
Posts: 2
backticks

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

Reply With Quote
  #13  
Old 11-08-2002, 06:13 PM
stoic stoic is offline
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Pingdom Talks Top Web Hosting Cities and Countries Web Hosting News 2013-03-27 18:49:54
Whistleblower Site Cryptome Hacked, Infects PCs with Drive-By Exploits Web Hosting News 2012-02-14 14:48:24
Control Panel cPanel Launches New Apache Configuration Script Web Hosting News 2011-12-28 19:41:39
Web Host HostingZoom Adds Softaculous Auto-Installer to Hosting Plans Web Hosting News 2011-08-17 17:52:34
Web Host JaguarPC Adds Auto-Installer Softaculous to Hosting Plans Web Hosting News 2011-07-27 18:55:46


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?