hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : du -s -h multiple folders
Reply

Forum Jump

du -s -h multiple folders

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-30-2004, 06:37 AM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199

du -s -h multiple folders


I have user who has 3 different accounts. I want to create him an total used disk space.

Now is use:
(date; du -s -h /home/ttd1; du -s -h /home/ttd2) >.....txt

Problem is that it prints it like this into .txt file:
65MB /home/ttd1
56MB /home/ttd2
etc.

Is there a way to print total used diskspace on 1 line?

__________________
Code goes in and code comes out..



Sponsored Links
  #2  
Old 12-30-2004, 07:21 AM
sehe sehe is offline
Web Hosting Master
 
Join Date: Jun 2003
Posts: 962
try

(date; du -s -h -c /home/ttd1 /home/ttd2 ) > ....txt

  #3  
Old 12-30-2004, 07:26 AM
datums datums is offline
Web Hosting Master
 
Join Date: May 2003
Posts: 1,148
You can use awk to print the addition of the 2. sorry kind of tired to do it.

__________________
Datums Internet Solutions, LLC
Systems Engineering & Managed Hosting Services
Complex Hosting Consultants

Sponsored Links
  #4  
Old 12-30-2004, 08:05 AM
error404 error404 is offline
Web Hosting Master
 
Join Date: Dec 2004
Location: Canada
Posts: 1,076
Using awk:
Code:
(date; du -s /home/ttd1 /home/ttd2 | awk '{sum += $1} END { print sum / 1024 "M\n"}') > .....txt
sehe's solution is better though. Use built in functions where possible.

__________________
>> Keenan Tims
█▓▒░ I am currently looking for full-time work in the Vancouver area. Resume ░▒▓█
http://www.gotroot.ca/ | ktims@gotroot.ca | skype: keenan.tims

  #5  
Old 01-02-2005, 05:07 PM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199
sehe´s solution worked really well, thank you!

It now prints total option also

Is there a way to print empty line in txt and after that some text writed by me? Something like this:

65M /home/ttd1
56M /home/ttd2
121M total

Your account is allowed to have 200MB of used diskspace.

__________________
Code goes in and code comes out..

  #6  
Old 01-02-2005, 05:08 PM
amc-james amc-james is offline
Web Hosting Master
 
Join Date: Mar 2003
Location: New Jersey
Posts: 1,276
echo >> filename

__________________
James Cornman - jcornman@atlanticmetro.net
Atlantic Metro Communications - AS29838
Data Centers • Managed Hosting • Internet Access • VMware vCloud Partner

  #7  
Old 01-02-2005, 05:23 PM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199
Can you give me an example how to use that command? I tryed (date; echo >> ; du -s -h -c... It just gave me bash: syntax error near unexpected token `;'

Im also trying to google some howtos, but dont seem to find correct search words, any ideas?

__________________
Code goes in and code comes out..

  #8  
Old 01-02-2005, 05:32 PM
Captian_Spike Captian_Spike is offline
Web Hosting Master
 
Join Date: Nov 2003
Location: Canada
Posts: 881
You left the filename out, you want to use

... echo >> file.txt; ....

Or maby just use

... echo ;....

  #9  
Old 01-02-2005, 05:35 PM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199
Oh god im so tired, i get it work now really well.

Now i just got the idea of make auto-calculate free space

Like this:

65M /home/ttd1
56M /home/ttd2
121M total

Your account have 79MB of un-used diskspace left. 200MB is total space.

So, some script that calculates this 200-total and prints it out. Wow, this would be really good to my use

__________________
Code goes in and code comes out..

  #10  
Old 01-02-2005, 05:54 PM
sehe sehe is offline
Web Hosting Master
 
Join Date: Jun 2003
Posts: 962
for just empty line its only "echo" in this case

(date; du -s -h -c /tmp /var/tmp ; echo ; echo "Your account is allowed to have 200MB of used diskspace." ) > d.txt

(all on 1 line)

  #11  
Old 01-02-2005, 05:59 PM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199
Thx, that is working now really good. sehe you are nr.1

Im just hoping that some command will do this calculate operation

But, if there isnt such thing/command, thats no problem. Im really pleased allready

EDIT:
And big thanks to all who helped me on this issue!

__________________
Code goes in and code comes out..

  #12  
Old 01-02-2005, 06:26 PM
sehe sehe is offline
Web Hosting Master
 
Join Date: Jun 2003
Posts: 962
Code:
#!/bin/sh
#in mb
MAXSPACE=2000;
DIRS="/tmp /var/tmp"
date > d.txt
IFS=" ";
DU=`du -s --block-size=M -c $DIRS | tee -a d.txt`
echo >> d.txt
TOTAL=`echo $DU | tail -n 1 | cut -f1 | cut -dM -f1`
FREE=`expr $MAXSPACE - $TOTAL`
if [ $FREE -le 0 ]; then
        OVER=`expr 0 - $FREE`;
        echo "you have no space left (max $MAXSPACE MB)! used $OVER MB too much" >> d.txt
else
        echo "still $FREE of $MAXSPACE MB free" >> d.txt
fi
might work, does here, is ugly, might breaks things

  #13  
Old 01-02-2005, 07:13 PM
vanHelsing vanHelsing is offline
Junior Guru
 
Join Date: Apr 2004
Posts: 199
Wow, thx! I will test it soon..

__________________
Code goes in and code comes out..

Reply

Related posts from TheWhir.com
Title Type Date Posted
Single Tweet Brings Dropbox DMCA Takedown Policy into Spotlight Web Hosting News 2014-03-31 04:30:00
Name Collisions Could Pose Potential Problem for Web Hosts Web Hosting News 2014-01-13 14:33:48
Comodo Makes Updates to Its Backup and Cloud Storage Services Web Hosting News 2013-12-24 13:32:31
IceWEB Releases Version 3.0 of Cloud Storage Solution Web Hosting News 2013-08-28 11:11:13
Cloud File Sharing Software ownCloud Launches Beta of Updated Community Version Web Hosting News 2012-09-04 17:09:04


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?