#!/bin/ksh # # report on a list of files # integer size=0 integer totalsize=0 integer count=0 integer largest=0 integer smallest=9999999999 countem() { size=`wc -c $1 | nawk '{print $1}'` (( totalsize+=size )) (( count+=1 )) } minormax() { if (( $size > $largest )); then largest=$size largestfn=$infile fi if (( $size < $smallest )); then smallest=$size smallestfn=$infile fi } if (( $# <= 1 )); then echo "What do you want to process \c" read ifiles else ifiles=$* fi echo Report generated on `uname -n` on `date` echo Report on files $ifiles for infile in $ifiles do if [[ ! -r $infile ]]; then echo "Error - input file $infile is not readable" continue fi countem $infile minormax done echo "Number of files: $count" echo "Total size: $totalsize" echo "Largest file is $largestfn and is $largest bytes" echo "Smallest file is $smallestfn and is $smallest bytes"