| kookie 2004-02-23, 9:34 am |
| Hi, I am sitting here getting crazy about my little mailbin-script
that wont work the way I want it to.
It is supposed to check if files are compressed and if they are,
uncompress before sending.
But instead it seems to compress uncompressed files before sending...
anyone know what might be wrong?
#!/bin/zsh
if [ $# -lt 2 ]
then
echo "Usage\n"
echo " $0 <address> <files>"
exit 3
fi
dst=$1
shift
for a in $*
do
if [a \! -r $a ]
then
echo "Cannot access file: $a"
err=1
fi
done
if [ "X$err" != "X" ]
then
exit 2
fi
tmpdir=/usr/tmp/mailbin
if [ \! -d $tmpdir ]
then
mkdir $tmpdir
chmod 777 $tmpdir
fi
for a in $*
do
bas=$( basename $a )
b=$tmpdir/$( basename $a )
# Check if file is compress(1)ed, then uncompress it first
if [ "X$a:r" = "Xgz" ]
then
ln -s $a $b.gz
elif uncompress < $a > $b.uZ 2>/dev/null
then
if [ "X$b:e" = "XZ" ]
then
bas=$bas:r
fi
gzip < $b.uZ > $b.gz
rm $b.uZ
else
gzip < $a > $b.gz
fi
uuencode $bas.gz < $b.gz > $b.gz.uu
mail $dst > $b.gz.uu
rm $b.gz $b.gz.uu
done
rmdir $tmpdir 2>/dev/null
exit 0
|