![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Total file size of a subset list | tekster757 | UNIX for Dummies Questions & Answers | 3 | 03-21-2008 09:27 AM |
| grep running total/ final total across multiple files | MrAd | UNIX for Dummies Questions & Answers | 5 | 05-08-2007 10:03 AM |
| how to generate a random list from a given list | mskcc | Shell Programming and Scripting | 3 | 05-30-2006 12:30 AM |
| Comparing a distinct value in 1 list with another list | manualvin | Shell Programming and Scripting | 6 | 06-22-2004 03:42 AM |
| how to list dir only | stephettt | UNIX for Dummies Questions & Answers | 2 | 02-22-2004 07:34 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
There's no need for the fancy execs, just do this:
Code:
while read line
do
# some stuff
done < $WORKLIST
Code:
echo $line
usage=`du -hs /Volumes/image/$line | awk -F/ '{print $1}'`
total_usage=`expr $total_usage + $usage`
echo $usage
|
|
|||
|
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. |
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |