home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2132 / vrfy
Encoding:
Korn shell script  |  1990-12-28  |  1.6 KB  |  74 lines

  1. #!/bin/ksh
  2.  
  3. ulimit -c 0        # prevent creation of core dumps
  4.  
  5. # verify the existence of a user name or alias on a given machine
  6. #
  7. # sample usage:
  8. #    vrfy cgsp@sprite
  9. #    vrfy montnaro
  10. #    vrfy lorensen@dwaskill egan smithwd@crd
  11.  
  12. if [ $# = 0 ] ; then
  13.     echo "usage: `basename $0` alias ..."
  14.     echo "       where alias can be of the form \"user@node\" or \"user\""
  15.     exit 1
  16. fi
  17.  
  18. while [ $# -gt 0 ] ; do
  19.     alias=`echo $1 | sed -e 's/@.*//'`
  20.     node=`echo $1 | sed -e 's/^[^@]*$//' -e 's/\(.*\)@\(.*\)/\2/'`
  21.  
  22.     if [ x$node = x ] ; then
  23.     node=`hostname`
  24.     fi
  25.  
  26.     # try to open connection to SMTP server on $node. No real provision is
  27.     # made for errors in attempts to connect, unless the node is unknown.
  28.     /usr/ucb/telnet $node 25 2>/dev/null |&
  29.  
  30.     read -p line    # Trying...
  31.     if [ "$line" = "$node: unknown host" ] ; then
  32.     print -p quit
  33.     echo $line
  34.     shift
  35.     continue
  36.     fi
  37.  
  38.     read -p line    # Connected ...
  39.     read -p line    # Escape ...
  40.     read -p line    # 220 ...
  41.  
  42.     # check to see if we connected okay
  43.     if [ "${line%% *}" != "220" ] ; then
  44.     echo Unable to connect to host $node:
  45.     shift
  46.     continue
  47.     fi
  48.  
  49.     # ask the SMTP server about $alias
  50.     print -p "vrfy $alias"
  51.     read -p line
  52.  
  53.     if [ "${line%% *}" = "550" ] ; then
  54.     # unknown user
  55.     echo "${line#* } on host $node."
  56.     elif [ "${line%%-*}" = "250" -o "${line%% *}" = "250" ] ; then
  57.     # one or more 250 lines follow with the alias expansion
  58.     print -n "$alias@$node == "
  59.     while [ "${line%%-*}" = "250" ] ; do
  60.         echo "${line#*-}"
  61.         print -n "    + "
  62.         read -p line
  63.     done
  64.     echo "${line#* }"
  65.     else
  66.     # unknown response from SMTP
  67.     echo "${line}"
  68.     fi
  69.  
  70.     print -p "quit"
  71.  
  72.     shift
  73. done
  74.