joe@auspyr.UUCP (Joe Angelo) (07/11/87)
[[ sent to alt.sources, comp.sources.unix ]]
This is the sort of thing we aren't likely to see (anymore) in a moderated
news group... [[ no, I'm not trying to start anything!! ]]
-------------------------------------------------------------------------
echo >/dev/null '
I have seen lots of requests for a recursive UUCP script; most of which
generate a "uucp" command line at the end of a "find"; ei: find -exec uucp.
Yukky and boring. Well, my method is not much better.
The attached script will generate a C. file for the remote system
and place it in the UUCP queque dirs (if permissions provide, otherwise,
the file is saved elsewhere; like /tmp). The script works for V7, BSD,
and HoneyDanber UUCP since the format of C. files is exactly the same;
even the name is VERY similar.
The only problem might be that some systems use a 5 character instead of
a 6 character UUCP ID string in the name of the C. file; it is easy to
fix if you have one of these systems -- look for the sick sed line.
There are some problems expanding .. and ../../../../.., but what the
heck -- this script was mostly designed for internal xfer of large
directories of source code and was found to be quite useful.
Any/all suggestions/warnings/impeachments welcome...
--
"Need input. Joe Angelo, Sr. Sys. Engineer @ Austec, Inc., San Jose, CA.
More input. ARPA: auspyr!joe@lll-tis[-b].arpa PHONE: [408] 279-5533
Ahhh, input!" UUCP: {sdencore,cbosgd,ptsfa,dana}!aussjo!joe
UUCP: {amdahl,lll-tis,imagen,necntc,dlb,sci,altnet}!auspyr!joe
'
# uuqr -- takes file name list from stdin or args (via find) and generates
# a C. file for uucp in the name of the remote system.
#
# usage:
#
# uuqr [dirs] system!directory
#
# examples:
#
# uuqr /tmp anysystem! xfer all in /tmp to anysystem!~nuucp/tmp/
# uuqr /tmp anysystem!/foo xfer all in /tmp to anysystem!/foo/tmp
# uuqr /tmp anysystem!/ xfer all in /tmp to anysystem!/tmp
# uuqr . anysystem!/duplicate xfer all in . to anysystem!/duplicate
#
# uuqr anysystem xfer all f-names from stdin to anysystem!~nuucp
# uuqr anysystem!/tmp xfer all f-namme from stdin to anysystem!/tmp
case $# in
0)
echo Usage: $0 '[dirs] system!directory
Where: dirs is a find(1) dir_name or nothing to denote
that file name list comes from standard input'
exit
;;
esac
#
# UUCP queue organization
#
# Set TYPE to: If:
# LINEAR /usr/spool/uucp contains FILES in form of C.*, D.*, X.*.
# SUBDIRS /usr/spool/uucp contains DIRS in form of C. D. X., D.hostname.
# HONEYBABY /usr/spool/uucp contains DIRS for each remote host.
TYPE=HONEYBABY
TYPE=LINEAR
TYPE=SUBDIRS
PWD=`pwd`
DIR=/usr/spool/uucppublic
#
# USER=$LOGNAME if SYSV
#
USER=$USER
for arg in $*
do
case "$arg" in
*!*)
HOST=`echo "$arg" | cut -d! -f1`
XDIR=`echo "$arg" | cut -d! -f2`
DIR=`echo $XDIR | awk ' {
if( substr($1,1,1) != "/" )
printf("/usr/spool/uucppublic/%s\n", $1)
else
printf("%s\n", $1)
}'`
;;
*) LIST="$LIST $arg"
;;
esac
done
#
# generate the directory name to store the file into
#
SPOOLDIR=/usr/spool/uucp
case "$TYPE" in
HONEYBABY) SPOOLDIR="/usr/spool/uucp/$HOST"
if test ! -d $SPOOLDIR
then
mkdir $SPOOLDIR 1>/dev/null 2>&1
fi
;;
LINEAR) SPOOLDIR="/usr/spool/uucp" ;;
SUBDIRS) SPOOLDIR="/usr/spool/uucp/C." ;;
esac
OLDPLACE=$SPOOLDIR
#
# make sure spool dir exists
#
DIDERROR=/bin/false
if test ! -d "$SPOOLDIR"
then
echo $0: spool dir non existant, output saved elsewhere...
DIDERROR=/bin/true
SPOOLDIR=/tmp
fi
#
# make sure we can write to the spool dir,
# most portable way is to echo something into a file there; test -w nonstandard
#
echo neat_stuff > /tmp/WAMMO$$
if cp /tmp/WAMMO$$ $SPOOLDIR/WAMMO$$ 1>/dev/null 2>&1
then
neat=yup
else
echo $0: can not write to spooldir, output saved elsewere...
DIDERROR=/bin/true
SPOOLDIR=/tmp
fi
rm -f /tmp/WAMMO$$ $SPOOLDIR/WAMMO$$
#
# generate the hostname part of the C. file...
# usually 6 characters only -- change for more or less.
#
HOSTPART=`echo $HOST | sed 's/^\(......\)\(.*\)/\1/'`
#
# generate a UNIQ ID string
#
STILLWORKING=/bin/true
tmpid=$$
while $STILLWORKING
do
# edit below if you have 6 character UUCP ids and not 5...
UUCP_ID=`echo $tmpid | sed '
s/^\([0-9][0-9][0-9][0-9]\)$/A\1/
s/^\([0-9][0-9][0-9]\)$/AA\1/
s/^\([0-9][0-9]\)$/AAA\1/
s/^\([0-9]\)$/AAAA\1/'`
CFILE=$SPOOLDIR/C.$HOSTPART$UUCP_ID
if test ! -f $CFILE
then
break
fi
tmpid=`expr $tmpid + 1`
done
echo $0: saving output in $CFILE
#
# is filename list from args or stdin?
#
(
if test ! -s "$LIST"
then
find $LIST -type f -print
else
echo stdin
while read FILENAME
do
echo $FILENAME
done
fi
) | awk '
{
# convert relative to absolute.
# keep absolute as is.
if( substr($1,1,1) != "/" )
name="'$PWD'/"$1
else
name=$1
printf("S %s '$DIR'/%s '$USER' -dc D.0 777\n", name, $1);
}' | tr -s '/' > $CFILE
if $DIRERROR
then
echo $0: someday, you should move $CFILE to $OLDPLACE
else
echo $0: $CFILE ready, now call the remote system...
fi
--
"Need input. Joe Angelo, Sr. Sys. Engineer @ Austec, Inc., San Jose, CA.
More input. ARPA: auspyr!joe@lll-tis[-b].arpa PHONE: [408] 279-5533
Ahhh, input!" UUCP: {sdencore,cbosgd,ptsfa,dana}!aussjo!joe
UUCP: {amdahl,lll-tis,imagen,necntc,dlb,sci,altnet}!auspyr!joe