Results 1 to 13 of 13
Thread: du -s -h multiple folders
-
12-30-2004, 06:37 AM #1Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
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..
-
12-30-2004, 07:21 AM #2Web Hosting Master
- Join Date
- Jun 2003
- Posts
- 976
try
(date; du -s -h -c /home/ttd1 /home/ttd2 ) > ....txt
-
12-30-2004, 07:26 AM #3Web Hosting Master
- Join Date
- May 2003
- Posts
- 1,151
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
-
12-30-2004, 08:05 AM #4Web Hosting Master
- Join Date
- Dec 2004
- Location
- Canada
- Posts
- 1,097
Using awk:
Code:(date; du -s /home/ttd1 /home/ttd2 | awk '{sum += $1} END { print sum / 1024 "M\n"}') > .....txt
-
01-02-2005, 05:07 PM #5Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
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..
-
01-02-2005, 05:08 PM #6Web Hosting Master
- Join Date
- Mar 2003
- Location
- Sioux Falls, SD
- Posts
- 1,282
echo >> filename
James Cornman
365 Data Centers - AS19151/AS29838
Colocation • Network Connectivity • Managed Infrastructure Services
-
01-02-2005, 05:23 PM #7Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
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..
-
01-02-2005, 05:32 PM #8Web 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 ;....
-
01-02-2005, 05:35 PM #9Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
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 useCode goes in and code comes out..
-
01-02-2005, 05:54 PM #10Web Hosting Master
- Join Date
- Jun 2003
- Posts
- 976
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)
-
01-02-2005, 05:59 PM #11Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
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..
-
01-02-2005, 06:26 PM #12Web Hosting Master
- Join Date
- Jun 2003
- Posts
- 976
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
-
01-02-2005, 07:13 PM #13Junior Guru
- Join Date
- Apr 2004
- Posts
- 200
Wow, thx! I will test it soon..
Code goes in and code comes out..