GELINASJ@CMR001.BITNET (12/30/89)
This csh script can be used to list side by side the files of similar
directories -perhaps on different apollo nodes- and the disk space used.
It is slow and, hum..., not elegant, but helps me to keep in sync
the /usr/local/bin directories on our 3 DN4000 cluster.
If you want to speed it up or translate it to sh or FORTRAN, please
feel free to do so. And a happy new year to all.
------------------------cut here---------------------------------
#!/bin/csh
# joindu [directory list]
#
# Creates a joint listing of disk space used in directories
# For example,
# % joindu //node_[1-3]/usr/local/bin
# will produce on standard output a 3 column listing
# of <du -s> of each directory with a TOTAL line.
# <gelinasj@cmr001.bitnet>
onintr cleanup
# Header line with date and time
if (! $#argv) set argv=(".")
set date=`date`
echo " JOINT DISK USAGE on $date[1], $date[3] $date[2] \
$date[6], at $date[4]" >! /tmp/joindu$$.dirs
# Reverse the arguments and make a list of directory names
set dirs=
foreach d ($*)
set dirs=($d $dirs)
echo \#${#dirs}: $d >>/tmp/joindu$$.dirs
end
# Make a sorted, unique list of all files names with 0 blocks
apply ls $* | \
sort -u | \
awk '{print $1,0}' - > /tmp/joindu$$.miss
# Initialise the database with a dummy void directory
cp /tmp/joindu$$.miss /tmp/joindu$$.all
# Join on the file names (first field)
foreach d ($dirs)
(cd $d; /bin/du -s *) | \
awk '{print $2,$1}' - | \
sort -m +0 -1 +1 -2 -dr - /tmp/joindu$$.miss | \
sort -um +0 -1 - | \
join - /tmp/joindu$$.all > /tmp/joindu$$.t
mv /tmp/joindu$$.t /tmp/joindu$$.all
end
# align the output, sum the block counts (skip the last column)
awk 'NR == 1 { nf=NF \
printf "\n%15s" , " " \
for( i = 1 ; i < nf-1 ; i++ ) \
printf " #%2d" , i \
} \
{ printf "\n%15s" , substr( $1, 0, 15 ) \
for( i = 2 ; i < nf ; i++ ) \
{ \
printf "%8d" , $i \
s[i] += $i \
} \
} \
END { printf "\n\n%15s" , "TOTAL" \
for( i = 2 ; i < nf ; i++ ) \
{ \
printf "%8d" , s[i] \
} \
printf "\n" \
}' /tmp/joindu$$.all | \
cat /tmp/joindu$$.dirs -
# Clean up /tmp
cleanup:
rm -f /tmp/joindu$$.{all,dirs,miss,t}
------------------------cut here---------------------------------
J. GELINAS (gelinasj@cmr001.bitnet)