du from list with du of list total


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting du from list with du of list total
# 1  
Old 05-01-2008
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  
Old 05-01-2008
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  
Old 05-02-2008
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  
Old 05-04-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total count in each category for given file list

I have list of file names in filename.txt below is file format >>File1 _________________________ 01~12345~Y~YES~aaaaa~can 02~23456~N~NO~bbbbb~can . . . 99~23__________________________ Need to find total count from each file depending on specific string and add them to have total count... (17 Replies)
Discussion started by: santoshdrkr
17 Replies

2. Shell Programming and Scripting

Copy list of files from a keyword list to another directory

Hello, I have a folder with a massive amount of files, and I want to copy out a specific subset of the files to a new directory. I would like to use a text file with the filenames listed, but can't get it to work. The thing I'm hung up on is that the folder names in the path can and do have... (5 Replies)
Discussion started by: twjolson
5 Replies

3. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

5. Shell Programming and Scripting

Convert perl qw list to text file list?

Does anyone have a good example? I am having trouble looping.. Thanks (1 Reply)
Discussion started by: mrlayance
1 Replies

6. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

7. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

8. UNIX for Advanced & Expert Users

help with sorting sequence in Unix C:sort -t ':' +0 -1 -n +1 -2 +2 -3 -o list list

Hi List is 000|2008-07-17|556543|RTJ|35-RTGJ|EYT 465|2008-11-10|567789|GHJ|45-DGHH|ETU 533|2008-09-06|567789|GHJ|45-DGHH|ETU How does it do it? sort -t ':' +0 -1 -n +1 -2 +2 -3 -o list list (6 Replies)
Discussion started by: gurvinder
6 Replies

9. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies

10. UNIX for Dummies Questions & Answers

Total file size of a subset list

Hello! I'm trying to find out the total file size of a subset list in a directory. For example, I do not need to know the total file size of all the files in a directory, but I need to know what the total size is of say, "ls -l *FEB08*" in a directory. Is there any easy way of doing this? ... (3 Replies)
Discussion started by: tekster757
3 Replies
Login or Register to Ask a Question