Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Section - 8.07: How to configure dialup SLIP

( Part1 - Part2 - Part3 - Part4 - Part5 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Property taxes ]


Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 8.06: How do I do remote backup? (cont.)
Next Document: 8.08: Disabling software flow control; using RTS/CTS.
See reader questions & answers on this topic! - Help others by sharing your knowledge
[ formerly in section 1.606 part 5 ]

#!/bin/ksh

# SLIP login .profile
# Adapted from comp.unix.aix FAQ
# by Davide Migliavacca (davide.migliavacca@inferentia.it)
# $Revision: 1.14 $

# Set this variable != 0 to allow multiple logins from this userid

ALLOW_MULTIPLE_LOGINS=0

# NOTE: script currently determines destination IP address from the SLIP
# interface attributes, but it assumes a correspondence
#     ttyxx <-> slipxx
# (see the "IPADDRESS=" awk line)
# It relies on a client being able to read the IP address from
# the logon procedure output.


PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:/usr/local/bin:.

export PATH ENV HISTSIZE
#
# Search for a LCK-File for our tty if there is one
#
TTYDEV=`tty`
TTYBASENAME=`basename $TTYDEV`
TTYNUMBER=`echo $TTYBASENAME | sed -n -e "s/tty\([0-9]\{1,\}\)/\1/p"`

if [ -f /etc/locks/LCK..$TTYBASENAME ];
then SHPID=`cat /etc/locks/LCK..$TTYBASENAME`;
else {
/usr/bin/logger -t SLIP -p error "No LCK file for $TTYDEV"
 exit 64;
}
fi;


# Search for another login from this userid

OTHERSLIP=`ps -fu$USER |
      sed -n -e "s/^ *$USER  *[0-9][0-9]* .*-.*\/usr\/sbin\/slattach \(tty[0-9]\{1,\}\) *$/\1/p`;
if [ ! -z "$OTHERSLIP" ];
then
   if [ $ALLOW_MULTIPLE_LOGINS -eq 0 ];
   then
           echo "Sorry, you are already connected to $OTHERSLIP.";
           echo "Multiple logins are NOT allowed.";
           echo "For any question, contact helpdesk@inferentia.it";
           /usr/bin/logger -t SLIP -p warn "$USER: attempt to connect on $TTYBASENAME when already connected on $OTHERSLIP - refused";
           exit 64;
   fi
#else...
   /usr/bin/logger -t SLIP -p warn "$USER: multiple login allowed, now using also $TTYBASENAME";
fi
#
# Search for our own Shell to get the PID for checking against LCK-File
#

SH2PID=`ps -ft$TTYNUMBER |
        sed -n -e "s/^ *$USER  *\([0-9][0-9]*\) .*-.*sh *$/\1/p`

#
# Is it the the same PID as in the LCK File so that we can start working ??
DEBUG=0
if [ $DEBUG -eq 1 ];
then
   echo TTYDEV: $TTYDEV
   echo TTYBASENAME: $TTYBASENAME
   echo USER: $USER
   echo SHPID: $SHPID
   echo SH2PID: $SH2PID
fi
if [ "$SHPID" -eq "$SH2PID" ];
then
#  remove the LCK-File because slattach does not like it.
   rm -rf /etc/locks/LCK..$TTYBASENAME
#  Add RTS/CTS Handshakeing to our own tty: Better do it in /etc/rc,
#  using the program from the comp.unix.aix FAQ.
#  stty add rts
   SLIPLINE=`echo $TTYBASENAME | awk '//{print substr($1,4);}'`
   IPADDRESS=`lsattr -E -l sl$SLIPLINE -a dest 2>/dev/null | awk '//{print $2;}'`
   if [ -z "$IPADDRESS" ]
   then
   /usr/bin/logger -t SLIP -p error "$USER: attempt to use tty with no slip interface defined ($TTYBASENAME)"
   echo "This tty ($TTYBASENAME) has not been enabled for SLIP. Please try another one or contact the system administrator."
   exit 64
   fi
   echo SLIP starting. Your IP address is $IPADDRESS
   /usr/sbin/slattach $TTYBASENAME
# Get the pid of slattach so that we can kill him later on.
   SLPID=`ps -aef |
      sed -n -e "s/^ *$USER  *\([0-9][0-9]*\) .*-.*\/usr\/sbin\/slattach $TTYBASENAME *$/\1/p`
#  Just say that we are up.
   logger -t SLIP -p info "$USER: Starting up daemon (pid $SLPID) for [$IPADDRESS] on $TTYDEV"
else
# Something must be wrong with the LCK-File
  SH3PID=`ps -aef | awk ' {print $2}' | grep $SHPID`

  if [ ."$SH3PID" = ."" ]
  then
    SH3PID="NO_SUCH_PROCESS"
  fi

  if [ $SHPID = $SH3PID ]
    then
#  There is a living process which owns the LCK-File !!
   /usr/bin/logger -t SLIP -p error "$USER: Cannot remove LCK file for $TTYDEV (not owner)"
       exit 64
    else
#   Who the hell didn't remove the LCK-File (should never happen)
   /usr/bin/logger -t SLIP -p error "$USER: LCK file for $TTYDEV found with no owner"
       #echo `date` " LCK-File with no owner found !!!" >>$SLIPLOG
       exit 64
    fi
fi

if [ $DEBUG -eq 1]
then
   /usr/bin/logger -t SLIP -p debug "$USER: going to trap signals..."
fi
Nov 28 11:18:46 sauternes rexecd[21420]: connect from brachetto.inferentia.it

                                                                             # terminated )
trap "kill $SLPID; /usr/bin/logger -t SLIP -p info \"$USER: Killing daemon (pid $SLPID) for $TTYDEV\"; exit 0" 1

if [ $DEBUG -eq 1]
then
   trap "/usr/bin/logger -t SLIP -p debug \"$USER: trap ERR\"" ERR
   trap "/usr/bin/logger -t SLIP -p debug \"$USER: trap 0\"" 0
   trap > /tmp/trap.$TTYBASENAME.log
   /usr/bin/logger -t SLIP -p debug "$USER: trap returns $?..."
fi

# We  will have a nice sleep and nice dreamings
if [ $DEBUG -eq 1]
then
   /usr/bin/logger -t SLIP -p debug "$USER: going to sleep-loop..."
fi

while [ true ];
do
sleep 60;
done

# Sanity check (should never happen...)
/usr/bin/logger -t SLIP -p error "$USER: ERROR: .profile broken"

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.unix.aix Frequently Asked Questions (Part 5 of 5)
Previous Document: 8.06: How do I do remote backup? (cont.)
Next Document: 8.08: Disabling software flow control; using RTS/CTS.

Part1 - Part2 - Part3 - Part4 - Part5 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
bofh@mail.teleweb.pt (Jose Pina Coelho)





Last Update March 27 2014 @ 02:11 PM