#!/bin/sh

# These commands get the hostname and IP address of the machine 
# that is talking to us over port 79 (the finger port).

Host=`netstat | sed -n -e "s/\.[0-9][0-9]* [ ]*EST.*//" -e "s/.*fing[e]*[r]* [ ]*//p"`
IP=`netstat -n | sed -n -e "s/\.[0-9][0-9]* [ ]*EST.*//" -e "s/.*\.79 [ ]*//p"`

# These lines check to see if I am logged in from home in order to
# inform less experienced people which port to use for talk.

if [ -r $HOME/.rem.tty ]
then
   mytty=`cat $HOME/.rem.tty`
else 
   mytty=""
fi

# These lines are self-explanatory.

thisHost=`hostname`
theDate=`date`

# and this one should be changed to whatever your workstation is...

myWS="magnesium.cchem.berkeley.edu"

$HOME/bin/backfinger $Host $IP

# Print out the expected finger information and give some interesting info.

cat $HOME/.realplan
echo _________________________________________________________________________
echo "You are fingering me from $Host ($IP)  Who are you?" 
echo To talk to me, use \"talk $USER\@$myWS $mytty\"
echo _________________________________________________________________________
echo "$thisHost :  Fingering from $Host ($IP) on $theDate" | \
      /usr/lib/sendmail $USER
