The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Total file size of a subset list tekster757 UNIX for Dummies Questions & Answers 3 03-21-2008 01:27 PM
grep running total/ final total across multiple files MrAd UNIX for Dummies Questions & Answers 5 05-08-2007 01:03 PM
how to generate a random list from a given list mskcc Shell Programming and Scripting 3 05-30-2006 03:30 AM
Comparing a distinct value in 1 list with another list manualvin Shell Programming and Scripting 6 06-22-2004 06:42 AM
how to list dir only stephettt UNIX for Dummies Questions & Answers 2 02-22-2004 11:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-01-2008
Movomito Movomito is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 27
du from list with du of list total

Hi there

i am relatively new to shell scripting and am stuck. I wrote (and borrowed parts of) a script that will read input from a text file and echo the file name and then give me the du of that file right underneath it in a nice clean way only after telling me the number files on which it will perform these actions. I would like it to also give me the combined du of all of the files in the list. Does anybody know how to do this?

here is my script:

#!/bin/bash
if [ ! $1 ]; then
echo missing arguments\(s\)
echo du-from-list.sh \<works-list\>
exit 1
fi

WORKLIST=$1
WORKSIZE=$du -hs /Volumes/image/$line


echo Total Number of Works
cat /Users/tbrc/scripts/ctc/lists/O1.txt | wc -l
sleep 5

exec 3<&0
exec 0<$WORKLIST
while read line
do

echo $line
du -hs /Volumes/image/$line | awk -F/ '{print $1}'

done
exec 0<&3


exit 0



Ideally i could something like
echo "total du"
and then the command



any help helps.

Thanks,
Movomito
  #2 (permalink)  
Old 05-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
There's no need for the fancy execs, just do this:

Code:
while read line
do
    # some stuff
done < $WORKLIST
To get a total, just store the output of the du command in a variable, and add them up as you go, something like this:

Code:
    echo $line
    usage=`du -hs /Volumes/image/$line | awk -F/ '{print $1}'`
    total_usage=`expr $total_usage + $usage`
    echo $usage
  #3 (permalink)  
Old 05-02-2008
Movomito Movomito is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 27
First off I am home taught so it may be that there is something that i am missing here. If i don't first run an exec how can i "read line" from workslist? But i did see what it was attempting and kept my execs and wrote the body of m script like this:

exec 3<&0
exec 0<$WORKLIST
while read line
do


echo $line
usage=`du -hs /Volumes/image/$line | awk -F/ '{print $1}'`
total_usage=`expr $total_usage + $usage`
echo $usage

#echo $line
#du -hs /Volumes/image/$line | awk -F/ '{print $1}'

done
exec 0<&3



and i got this error:

W00EGS1017426(this is the dir name)
expr: syntax error
3.2G(this is the individual directories size)


as you can see i am still getting the individual size output.

Thanks for the help, maybe you can make more sense of this than I can.
  #4 (permalink)  
Old 05-04-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Have a read of the REDIRECTION section of the bash man page to understand how input and output redirection works. The exec commands you were using were for duplication of file descriptors, which is useful in some scenarios, but unnecessarily complicated for your requirements.

For the expr calculation problem, it's because expr doesn't understand units in G. Take the -h option out of the du command line so that it doesn't output units of MB and GB.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0