Results 1 to 13 of 13
  1. #1

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

  2. #2
    Join Date
    Jun 2003
    Posts
    976
    try

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

  3. #3
    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

  4. #4
    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
    sehe's solution is better though. Use built in functions where possible.

  5. #5
    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. #6
    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

  7. #7
    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. #8
    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. #9
    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. #10
    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)

  11. #11
    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. #12
    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
    might work, does here, is ugly, might breaks things

  13. #13
    Wow, thx! I will test it soon..
    Code goes in and code comes out..

Posting Permissions

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