[mod.sources] uuque - a uuwizard's utility for uucp queue snooping

john@genrad.UUCP (John Nelson) (10/26/84)

This is a shell script that I've put together to check out the sorts of
things that have been queued up in the uucp queues.  I can only
guarantee it for rnews, rmail, and uucp copies, but with a little
hacking it could work for batched news, etc.  Any enhancements would be
welcome.
--
Ken Turkowski @ CADLINC, Palo Alto, CA
UUCP: {amd,decwrl,flairvax,nsc}!turtlevax!ken
ARPA: turtlevax!ken@DECWRL.ARPA

-----------------------------------------------------------------
echo x - uuque
cat >uuque <<'!Funky!Stuff!'
#! /bin/sh
# The user must have access to the /usr/spool/uucp/* directories and files.
# This can be easily done by making certain users members of the daemon
# and/or uucp groups.
# uusnap
cd /usr/spool/uucp
LUUNAME=`uuname -l`
verbose=false
system='*'

# Process flags
for arg
do
    case $arg in
	-v)
	    verbose=true
	    ;;
	-s)
	    echo Syntax: '-sSYSTEM'
	    ;;
	-s*)
	    arg=`expr $arg : '-s\(.*\)'`
	    system=`expr $arg : '\(.......\)'` || system=$arg
	    ;;
	*)
	    echo Unknown flag: $arg
	    ;;
    esac
done

# Check for outgoing work
for cmdfile in C./*
do
    test -f $cmdfile || continue
    othersys=`expr $cmdfile : 'C./C.\(.*\).....'`
    case $othersys in
	$system)
	    ;;
	*)
	    continue
	    ;;
    esac
    cmd=
    xfile=
    cat $cmdfile | {
	while read cmd arg1 arg2 arg3 extra
	do
	    case $cmd in
		S)				# uucp send
		    case $arg1 in
			D.${LUUNAME}X????)	# Remote execute file
			    xfile=$arg1
			    ;;
			D.${LUUNAME}?????)	# Data file ref'd by xfile
			    dfile=D.${LUUNAME}/$arg1
			    ;;
			*)		# Just a uucp -- no intertpretation
			    echo `ls -l $arg1 | awk '{print $4}'`\	 uucp $arg1 $othersys!$arg2 \($arg3\)
			    ;;
		    esac
		    ;;
		R)		# uucp receive
		    echo '	' uucp $othersys!$arg1 $arg2 \($arg3\)
		    ;;
		*)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra
		    continue ;;
	    esac
	done
	case $xfile in
	    "")			# uucp transfer
		continue
		;;
	esac
	cat D.${LUUNAME}X/$xfile | {	# complex transfer -- interpret xfile
	    while read xcmd arg1 arg2 extra
	    do
		case $xcmd in
		    U)
			from=$arg2!$arg1
			;;
		    F)
			;;
		    I)
			;;
		    Z)
			;;
		    C)
			case $arg1 in
			    rmail)
				from=`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
				echo `ls -l $dfile | awk '{print $4}'`\	 $arg1 $othersys!$arg2 \($from\)
				if $verbose
				then
				    echo -n '	 '
				    grep '^Subject:' $dfile || echo ''
				fi
				;;
			    rnews)
				echo `ls -l $dfile | awk '{print $4}'`\	 $arg1 $othersys  \($from\)
				if $verbose
				then
				    echo -n '	 '
				    grep '^Newsgroups:' $dfile
				    echo -n '	 '
				    grep '^Subject:' $dfile
				fi
				;;
			    *)
				echo `ls -l $dfile | awk '{print $4}'`\	 $arg1 $arg2 $extra [$othersys $dfile] \($from\)
				;;
			esac
			;;
		    *)
			echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2
			exit
			;;
		esac
	    done
	}
    }
done

# Check for incoming work
for cmdfile in X./*
do
    test -f $cmdfile || continue
    othersys=`expr $cmdfile : 'X./X.\(.*\).....'`
    case $othersys in
	$system)
	    ;;
	*)
	    continue
	    ;;
    esac
    comment=
    cat $cmdfile | {
	while read cmd arg1 arg2 extra
	do
	    case $cmd in
		U)
		    from=$arg2!$arg1
		    ;;
		Z)
		    ;;
		I)
		    ;;
		F)
		    if test -f D./$arg1
		    then
			dfile=D./$arg1
		    elif test -f XTMP/$arg2
		    then
			dfile=XTMP/$arg2
			comment="[EXECUTING]"
		    else
			continue 2
		    fi
		    ;;
		C)
		    xcmd=$arg1
		    xargs="$arg2 $extra"
		    case $arg1 in
			rmail)
			    from=$othersys!`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
			    echo `ls -l $dfile | awk '{print $4}'`\	 $xcmd $xargs $comment \($from\)
			    if $verbose
			    then
				echo -n '	 '
				grep '^Subject:' $dfile || echo ''
			    fi
			    ;;
			*)
			    echo `ls -l $dfile | awk '{print $4}'`\	 $xcmd $xargs $comment \($from\)
			    ;;
		    esac
		    ;;
		*)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra
		    continue ;;
	    esac
	done
    }
done
!Funky!Stuff!
chmod +x uuque
echo uuque extracted successfully
exit 0