Subject: How to automate pppd dialing with minicom

From: Rick Macdonald <[email-masked]>
Date: Wed, 21 Aug 1996 12:29:32 -0600 (MDT)

I've seen many people mention that they manually dial their
ISP with minicom and manually suspend minicom, then manually 
start pppd or whatever at each end.

The following is one way to automate this, free for your 
enjoyment!

I've been using minicom's runscript for automating this
proceedure for 2 or 3 years. I got the original script 
from Scott Barker, who is also on this list. I've tweeked
it alot over this time. I'm sure Scott and modified his setup 
even more. Some of it may have come from Slackware.

I haven't even bothered trying to improve the various tasks
and tests that are done, since it continues to do the job 
for me.

Note the use of sudo. I see that /dev/ttsS1 has permissions of

     crw-rw-rw-   1 root       4,  65 Aug 20 21:31 ttyS1

but I probably did the chmod o+rw before I started using sudo.
My guess is that it will work with the standard permissions
(crw------ or crw-rw----; I forget now).

Lastly, an update to pppd earlier this year now sends the
output from ip-up and the runscript to the twilight zone.
I haven't looked into getting those messages back somehow.
The main annoyance is that I no longer see the connection
rate of the modems.

--------------------------------------
pppdial script
--------------------------------------
#!/bin/sh

# this sets the phone number to dial
if [ "$1" = "" ]
then
   export PHONE=5551212
else
   export PHONE=$1
fi

# set these to your modem device and baud rate
DEVICE=ttyS1
SPEED=38400

# check if the device is locked
if [ -r /var/lock/LCK..$DEVICE ]; then
	echo Device $DEVICE is locked
        exit 1
fi

sudo rm -f /etc/ppp/ppp_is_up

# the command used to establish the modem connection (use chat if you like)
CONNECT="runscript /usr/local/lib/runscripts/pppscript_office"

# set these to your PPP login name and password (if runscript used to connect)
export LOGIN=my_login
export PASS=my_password

umask 000
# run the ppp daemon
sudo /usr/sbin/pppd connect "$CONNECT" lock defaultroute mru 296 \
                  name calgary6 \
                  3.3.3.3: /dev/$DEVICE $SPEED crtscts modem

echo
echo To abort, press ^C then execute pppkill
echo
echo -n Dialing...

# wait for pppd to start
while [ ! -r /var/run/ppp0.pid ]; do
   if [ `ps -aux | grep -c /usr/sbin/pppd` =  0 ]; then
      echo Aborted!
      exit 1
   fi
   sleep 1
done
echo Connected!

echo -n Negotiating ppp...

while [ ! -f /etc/ppp/ppp_is_up ]; do
   if [ `ps -aux | grep -c /usr/sbin/pppd` =  0 ]; then
      echo Aborted!
      exit 1
   fi
   sleep 1
done
echo OK!

echo =========================================
cat /etc/resolv.conf
echo =========================================

------------------------------------------
runscript file: /usr/local/lib/runscripts/pppscript_office
------------------------------------------
timeout 600

send "+++"
sleep 1
send "ATH"
sleep 1

send "ATZ"
expect {
       "OK"
       timeout 4 exit 1
}

RETRY1:
send "\r"
sleep 1
send "ATDT$(PHONE)"
expect {
       "CONNECT"     goto CONNECT
       "BUSY"        goto RETRY1
       "NO CARRIER"  goto RETRY1
       "NO DIALTONE" goto RETRY1
       timeout 60    goto RETRY1
}

CONNECT:

expect {
       "\r"          break
       timeout 1     break
}

send "\r"
sleep 1

expect {
       "word: "
       timeout 10 exit 1
}

sleep 1
send "$(PASS)\r\c"

expect {
       "annex1:"
       timeout 10 exit 1
}

sleep 1
send "ppp\r\c"

print "\r\n\r\nConnected OK. Negotiating ppp link...\r\n"

exit 0

--------------------------------------------
/etc/ppp/ip-up
--------------------------------------------
#!/bin/sh
#
# $Id: ip-up,v 1.1 1996/01/31 21:25:59 alvar Exp $
#
# This script is run by the pppd after the link is established.
# It should be used to add routes, set IP address, run the mailq 
# etc.
#
# This script is called with the following arguments:
#    Arg  Name               Example
#    $1   Interface name     ppp0
#    $2   The tty            ttyS1
#    $3   The link speed     38400
#    $4   Local IP number    12.34.56.78
#    $5   Peer  IP number    12.34.56.99

#
# The  environment is cleared before executing this script
# so the path must be reset
#
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

echo Connected OK to $5
if [ "$5" = "1.1.1.1" ]
then
   cp /etc/hosts_cuug /etc/hosts
   echo Setting nameserver for CUUG:
   cp /etc/resolv.conf.cuug /etc/resolv.conf 
elif [ "$5" = "2.2.2.2" ]
then
   cp /etc/hosts_vsl /etc/hosts
   echo Setting nameserver for VSL:
   cp /etc/resolv.conf.vsl /etc/resolv.conf 
else
   echo ***SKIPPING*** reset of nameserver, using:
fi

echo =========================================
cat /etc/resolv.conf
echo =========================================

# keep the link alive
ping -i 120 $5 > /dev/null 2>&1 &

echo $1 link initialized and ready for use

touch /etc/ppp/ppp_is_up

# last line

--------------------------------------------
/etc/ppp/ip-down
--------------------------------------------
#!/bin/sh
#
# $Id: ip-down,v 1.1 1996/01/31 21:25:59 alvar Exp $
#
# This script is run by the pppd _after_ the link is brought down.
# It should be used to delete routes, unset IP addresses etc.
#
# This script is called with the following arguments:
#    Arg  Name               Example
#    $1   Interface name     ppp0
#    $2   The tty            ttyS1
#    $3   The link speed     38400
#    $4   Local IP number    12.34.56.78
#    $5   Peer  IP number    12.34.56.99

#
# The  environment is cleared before executing this script
# so the path must be reset
#
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

killall -v ping

# last line

--------------------------------------------
/etc/sudoers
--------------------------------------------
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=ALL
rickm	ALL=ALL
ALL     ALL=/usr/sbin/pppd

...RickM...