Unix Programming - mailbin-script - zsh

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2004 > mailbin-script - zsh





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mailbin-script - zsh
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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com