[linux] PPP Chat Script

Chairil K. Kartakusuma (chairil@jiffy.printis.org)
Sat, 27 Jan 1996 21:50:39 +0700 (JVT)

Many have asked for this before, I might as well post it.

====== PPP-ON BEGINS ====== CUT HERE ==========
#!/bin/sh
#
# This is a *simple* ppp script (cuz I don't use PPP) B-)
# Modified off somebody elses'
#
# todo:
# - name this file ppp-on (or something)
# - as root,
# # chmod 4700 ppp-on
# # Run it as root, or if you don't want to 'su' first:
# - as root
# # chmod 4755 ppp-on
# # Run it as non-root.
#
# Note:
# If pppd is already setuid, no need to setuid the script.
#
# WARNING !! WARNING !! WARNING !!
# DO NOT USE THIS ON A MULTI-USER ENVIRONEMNT
# YOUR USERID AND PASSWORD *WILL* SHOW ON THE PROCESS TABLE.

# Directory where lock files live.
LOCKDIR=/var/spool/uucp

# 14.400bps modem use 57600, 28.800bps use 115200
DTE=57600

# Mine is USRobotics
# Put an 'OK' right after INIT string in the chat script.
# Modem init string 1
INIT1=ATZ
# Modem init string 2
INIT2="AT&FE1V1Q0X4B0&B1&H1&R2&N0&A3S11=55"
# Modem init string 3
INIT3="ATS10=255"

# Directory where PPP stuffs live.
# On Slakware 3.0 it;'s under /usr/sbin, others ?, dunno :0
PPPBIN=/usr/sbin

# cua0=COM1, cua1=COM2, etc.
DEVICE=cua1

# Gambir
PHONE=9,344-1333
USER=yourid
PASSWORD=yourpasswd

# If dynamic, leave the 'LOCAL_IP' blank.
LOCAL_IP=
# Leave this blank too if your ISP assigns it automatically.
# I put it the value anyway, just in case.
REMOTE_IP=192.215.248.193

# Check if the port is being used.
if [ -f $LOCKDIR/LCK..$DEVICE ]
then
echo "PPP device is locked"
exit 1
fi

# Set proper permissions for the device.
$PPPBIN/fix-cua $DEVICE

(
stty $DTE -tostop

if $PPPBIN/chat -v ABORT "NO CARRIER" ABORT BUSY "" $INIT1 OK $INIT2 OK $INIT3 OK ATDT$PHONE CONNECT "" ogin: $USER ssword: \\q$PASSWORD
then
$PPPBIN/pppd -detach debug crtscts modem netmask 255.255.255.0 \
mru 1500 defaultroute noipdefault /dev/$DEVICE
sleep 10
# If you have default route already, this is needed, since pppd does not
# delete it by default. If not, comment out the 'route' command.
route add default gw $REMOTE_IP
exit 0
else
echo "PPP call failed" 1>&2
exit 1
fi
) < /dev/$DEVICE > /dev/$DEVICE

====== PPP-ON ENDS ====== CUT HERE ==========

For ppp-off, chmod this 4755 or 4700 too.

====== PPP-OFF BEGINS ====== CUT HERE ==========
#!/bin/sh

# ppp0 is for the first ppp device.
DEVICE=ppp0
PORT=cua1

#
# If the ppp0 pid file is present then the program is running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
kill -INT `cat /var/run/$DEVICE.pid`
echo "Removing Lock File..."
rm -f /var/spool/uucp/*$PORT
#
# If unsuccessful, ensure that the pid file is removed.
#
if [ ! "$?" = "0" ]; then
echo "removing stale $DEVICE pid file."
rm -f /var/run/$DEVICE.pid
exit 1
fi
#
# Success. Terminate with proper status.
#
echo "$DEVICE link terminated"
exit 0
fi
#
# The link is not active
#
echo "$DEVICE link is not active"
exit 1
====== PPP-OFF ENDS ====== CUT HERE ==========

-- 
========================================================================
Chairil K. Kartakusuma, M.Sc.                  | SunOS / Solaris,      |
PRINTIS Information Systems Consultant         | AT&T/UnixWare SVR4    |
UNIX & Multi-Platform Client/Server Integrator | Linux, FreeBSD, OS/2  |
Jakarta, INDONESIA                             |=======================|
e-mail: chairilk@indo.net.id                   |   Abolish Software    |
        chairil@ibm.net                        |       Monopoly        |
        chairil@sns.com                        | Support Free Software |
========================================================================
-
START LANGGANAN:  kirimkan isi pesan "subscribe" ke linux-request@sdn.or.id
STOP LANGGANAN:	kirimkan isi pesan "unsubscribe" ke linux-request@sdn.or.id