Alias Lister For Users

Skip Montanaro montnaro at spyder.crd.ge.com
Thu Nov 22 05:07:11 AEST 1990


Everybody has a twist. Here's mine, written a couple of years ago.  It
handles aliases on remote machines and does full expansion by connecting to
the SMTP port of the node in the alias. It requires the Korn shell for "read
-p" and the "%%" operator on variables.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  vrfy
# Wrapped by montnaro at spyder on Wed Nov 21 13:02:16 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f vrfy -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"vrfy\"
else
echo shar: Extracting \"vrfy\" \(1670 characters\)
sed "s/^X//" >vrfy <<'END_OF_vrfy'
X#!/bin/ksh
X
Xulimit -c 0		# prevent creation of core dumps
X
X# verify the existence of a user name or alias on a given machine
X#
X# sample usage:
X#	vrfy cgsp at sprite
X#	vrfy montnaro
X#	vrfy lorensen at dwaskill egan smithwd at crd
X
Xif [ $# = 0 ] ; then
X    echo "usage: `basename $0` alias ..."
X    echo "       where alias can be of the form \"user at node\" or \"user\""
X    exit 1
Xfi
X
Xwhile [ $# -gt 0 ] ; do
X    alias=`echo $1 | sed -e 's/@.*//'`
X    node=`echo $1 | sed -e 's/^[^@]*$//' -e 's/\(.*\)@\(.*\)/\2/'`
X
X    if [ x$node = x ] ; then
X	node=`hostname`
X    fi
X
X    # try to open connection to SMTP server on $node. No real provision is
X    # made for errors in attempts to connect, unless the node is unknown.
X    /usr/ucb/telnet $node 25 2>/dev/null |&
X
X    read -p line	# Trying...
X    if [ "$line" = "$node: unknown host" ] ; then
X	print -p quit
X	echo $line
X	shift
X	continue
X    fi
X
X    read -p line	# Connected ...
X    read -p line	# Escape ...
X    read -p line	# 220 ...
X
X    # check to see if we connected okay
X    if [ "${line%% *}" != "220" ] ; then
X	echo Unable to connect to host $node:
X	shift
X	continue
X    fi
X
X    # ask the SMTP server about $alias
X    print -p "vrfy $alias"
X    read -p line
X
X    if [ "${line%% *}" = "550" ] ; then
X	# unknown user
X	echo "${line#* } on host $node."
X    elif [ "${line%%-*}" = "250" -o "${line%% *}" = "250" ] ; then
X	# one or more 250 lines follow with the alias expansion
X	print -n "$alias@$node == "
X	while [ "${line%%-*}" = "250" ] ; do
X	    echo "${line#*-}"
X	    print -n "	+ "
X	    read -p line
X	done
X	echo "${line#* }"
X    else
X	# unknown response from SMTP
X	echo "${line}"
X    fi
X
X    print -p "quit"
X
X    shift
Xdone
END_OF_vrfy
if test 1670 -ne `wc -c <vrfy`; then
    echo shar: \"vrfy\" unpacked with wrong size!
fi
chmod +x vrfy
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Skip (montanaro at crdgw1.ge.com)



More information about the Alt.sources mailing list