shell script - generate a report with dir and # files

shell script - generate a report with dir and # files

am 11.01.2008 20:51:30 von bhaveshah

Gurus,
I've a command which generates output as below:

foo.com shahb 485 /ms4/3C/12/70674
foo.com shahb Aix /ms4/62/12/67626
foo.com shahb Data_Growth /ms4/7C/1E/35066
foo.com shahb "Deleted Messages" /ms4/21/08/30698
foo.com shahb Drafts /ms2/31/1F/13832
foo.com shahb DR /ms4/32/06/96855

col 1 - domain
col2 - user
col3 - dir name
col3 - physical dir path

I have to write a script which generates a report for 1000 such users
with the no of files in each such dir. The report output should be
similar to:

User DIR # files
shahb Aix 445
shahb DR 2000

I can get the #files in each dir with the for loop as below:

for DIR in `/opt/sbin/mbox_path foo.com shahb | awk -F"\t" '{print
$4}'`; do echo "$DIR"; ls $DIR | wc -l | tr -d " "; done

This will give me the #files in folder but don't know who to relate to
the folder name and generate a report.

Any Help is greately appreciated.
Thanks & Regards

Re: shell script - generate a report with dir and # files

am 12.01.2008 04:21:30 von Janis Papanagnou

explor wrote:
> Gurus,
> I've a command which generates output as below:
>
> foo.com shahb 485 /ms4/3C/12/70674
> foo.com shahb Aix /ms4/62/12/67626
> foo.com shahb Data_Growth /ms4/7C/1E/35066
> foo.com shahb "Deleted Messages" /ms4/21/08/30698
> foo.com shahb Drafts /ms2/31/1F/13832
> foo.com shahb DR /ms4/32/06/96855
>
> col 1 - domain
> col2 - user
> col3 - dir name
> col3 - physical dir path
>
> I have to write a script which generates a report for 1000 such users
> with the no of files in each such dir. The report output should be
> similar to:
>
> User DIR # files
> shahb Aix 445
> shahb DR 2000
>
> I can get the #files in each dir with the for loop as below:
>
> for DIR in `/opt/sbin/mbox_path foo.com shahb | awk -F"\t" '{print
> $4}'`; do echo "$DIR"; ls $DIR | wc -l | tr -d " "; done
>
> This will give me the #files in folder but don't know who to relate to
> the folder name and generate a report.
>
> Any Help is greately appreciated.
> Thanks & Regards
>

One possibility...

printf "User\tDIR\t# files\n"
your_data_generator | while IFS=$'\t' read -r domain user dir physical
do
printf "%s\t%s\t%d\n" "$user" "$dir" $( ls "$dir" 2>/dev/null | wc -l )
done


Janis