Path: utzoo!utgpu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!crdgw1!montnaro From: montnaro@spyder.crd.ge.com (Skip Montanaro) Newsgroups: alt.sources Subject: Re: Alias Lister For Users Message-ID: Date: 21 Nov 90 18:07:11 GMT References: <1990Nov17.023351.16824@lokkur.dexter.mi.us> <39929@ut-emx.uucp> Sender: news@crdgw1.crd.ge.com Reply-To: montanaro@crdgw1.ge.com (Skip Montanaro) Followup-To: alt.sources Organization: GE Corporate Research & Development, Schenectady, NY Lines: 105 In-reply-to: mic@ut-emx.uucp's message of 19 Nov 90 04:09:10 GMT 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 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@sprite X# vrfy montnaro X# vrfy lorensen@dwaskill egan smithwd@crd X Xif [ $# = 0 ] ; then X echo "usage: `basename $0` alias ..." X echo " where alias can be of the form \"user@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