|
このページは大阪弁化フィルタによって翻訳生成されたんですわ。 |
|
TUCOWS NETWORK |
LINUXBERG | TUCOWS | FREETHEMES | GAMINGPLACE | eBarn | PDA Central | HOME |
|
|
|
H
HOWTO
's (HOWTOs in html) plain text (HOWTOs in plain text for printing) html'd (Mini-HOWTOs) plain text (Mini-HOWTOs) LDP Additions (Latest from LDP) Other Formats (LDP Other Formats) Translations (LDP Other Languages) Unmaintained (LDP Unmaintained)
Contrib
|
15. Automating your connections - Creating the connection scriptsWhilst you can continue to log in by hand as shown above, it is much neater to set up some scripts to do this automatically for you. A set of scripts automates the log in and PPP start up so all you have to do (as root or as a member of the PPP group) is issue a single command to fire up your connection. 15.1 Connection scripts for User name/Password AuthenticationIf your ISP does NOT require the use of PAP/CHAP, these are the scripts for you! If the ppp package installed correctly, you should have two example files.
For PPP 2.1.2 they are in for PPP-2.1.2
and for PPP-2.2
Now, if you are using PPP 2.1.2, I strongly urge you to delete the sample files. There are potential problems with these - and don't tell me they work fine - I used them for ages too (and recommended them in the first version of this HOWTO)! For the benefit of PPP 2.1.2 users, here are BETTER template versions, taken from the PPP 2.2 distribution. I suggest you copy and use these scripts instead of the old PPP-2.1.2 scripts. 15.2 The ppp-on scriptThis is the first of a PAIR of scripts that actually fire up the connection.
#!/bin/sh
#
# Script to initiate a PPP connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command. However, it is simple.
#
# These are the parameters. Change as needed.
TELEPHONE=555-1212 # The telephone number for the connection
ACCOUNT=george # The account name for logon (as in 'George Burns')
PASSWORD=gracie # The password for this account (and 'Gracie Allen')
LOCAL_IP=0.0.0.0 # Local IP address if known. Dynamic = 0.0.0.0
REMOTE_IP=0.0.0.0 # Remote IP address if desired. Normally 0.0.0.0
NETMASK=255.255.255.0 # The proper netmask if needed
#
# Export them so that they will be available to 'ppp-on-dialer'
export TELEPHONE ACCOUNT PASSWORD
#
# This is the location of the script which dials the phone and logs
# in. Please use the absolute file name as the $PATH variable is not
# used on the connect option. (To do so on a 'root' account would be
# a security hole so don't ask.)
#
DIALER_SCRIPT=/etc/ppp/ppp-on-dialer
#
# Initiate the connection
#
#
exec /usr/sbin/pppd debug /dev/ttySx 38400 \
$LOCAL_IP:$REMOTE_IP \
connect $DIALER_SCRIPT
Here is the ppp-on-dialer script:-
#!/bin/sh
#
# This is part 2 of the ppp-on script. It will perform the connection
# protocol for the desired connection.
#
/usr/sbin/chat -v \
TIMEOUT 3 \
ABORT '\nBUSY\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' \rAT \
'OK-+++\c-OK' ATH0 \
TIMEOUT 30 \
OK ATDT$TELEPHONE \
CONNECT '' \
ogin:--ogin: $ACCOUNT \
assword: $PASSWORD
For PPP-2.2, the
#!/bin/sh
######################################################################
#
# Determine the device to be terminated.
#
if [ "$1" = "" ]; then
DEVICE=ppp0
else
DEVICE=$1
fi
######################################################################
#
# 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`
#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
if [ ! "$?" = "0" ]; then
rm -f /var/run/$DEVICE.pid
echo "ERROR: Removed stale pid file"
exit 1
fi
#
# Success. Let pppd clean up its own junk.
echo "PPP link to $DEVICE terminated."
exit 0
fi
#
# The ppp process is not running for ppp0
echo "ERROR: PPP link is not active on $DEVICE"
exit 1
15.3 Editing the supplied PPP startup scriptsAs the new scripts come in two parts, we will edit them in turn. The ppp-on scriptYou will need to edit the script to reflect YOUR user name at your ISP, YOUR password at your ISP, the telephone number of your ISP. Each of the lines like Also, as you are setting the IP number (if you need to) in the
$LOCAL_IP:$REMOTE_IP \ Also, make sure that the shell variable DIALER_SCRIPT points at
the full path and name of the dialer script that you are actually going
to use. So, if you have moved this or renamed the script,
make sure you edit this line correctly in the The ppp-on-dialer scriptThis is the second of the scripts that actually brings up our ppp link. Note: a chat script is normally all on one line. the backslashes are used to allow line continuations across several physical lines (for human readability) and do not form part of the script itself. However, it is very useful to look at it in detail so that we understand what it is actually (supposed) to be doing! 15.4 What a Chat script means...A chat script is a sequence of If we are to send something WITHOUT receiving anything first, we
must use an empty expect string (indicated by
The chat line in our template is:-
exec /usr/sbin/chat -v Invoke chat, the -v tells chat to copy ALL its I/O into the system log (usually /var/log/messages). Once you are happy that the chat script is working reliably, edit this line to remove the -v to save unnecessary clutter in your syslog.
TIMEOUT 3 This sets the timeout for the receipt of expected input to three seconds. You may need to increase this to say 5 or 10 seconds if you are using a really slow modem!
ABORT '\nBUSY\r' If the string BUSY is received, abort the operation.
ABORT '\nNO ANSWER\r' If the string NO ANSWER is received, abort the operation
ABORT '\nRINGING\r\n\r\nRINGING\r' If the (repeated) string RINGING is received, abort the operation. This is because someone is ringing your phone line!
" \rAT Expect nothing from the modem and send the string AT.
OK-+++\c-OK ATH0 This one is a bit more complicated as it uses some of chat's error recovery capabilities. What is says is...Expect OK, if it is NOT received (because the modem is not in command mode) then send +++ (the standard Hayes-compatible modem string that returns the modem to command mode) and expect OK. Then send ATH0 (the modem hang up string). This allows your script to cope with the situation of your modem being stuck on-line!
TIMEOUT 30 Set the timeout to 30 seconds for the remainder of the script. If you experience trouble with the chat script aborting due to timeouts, increase this to 45 seconds or more.
OK ATDT$TELEPHONE Expect OK (the modem's response to the ATH0 command) and dial the number we want to call.
CONNECT '' Expect CONNECT (which our modem sends when the remote modem answers) and send nothing in reply.
ogin:--ogin: $ACCOUNT Again, we have some error recovery built in here. Expect the login prompt (...ogin:) but if we don't receive it by the timeout, send a return and then look for the login prompt again. When the prompt is received, send the username (stored in the shell variable $ACCOUNT).
assword: $PASSWORD Expect the password prompt and send our password (again, stored in a shell variable). This chat script has reasonable error recovery capability. Chat has
considerably more features than demonstrated here. For more information
consult the chat manual page ( Starting PPP at the server endWhilst the ppp-on-dialer script is fine for servers that automatically start pppd at the server end once you have logged in, some servers require that you explicitly start PPP on the server. If you need to issue a command to start up PPP on the server, you DO need to edit the ppp-on-dialer script. At the END of the script (after the password line) add an additional
expect send pair - this one would look for your login prompt (beware
of characters that have a special meaning in the Bourne shell - such as
$ and Once chat has found the shell prompt, chat must issue the ppp start up command required for your ISPs PPP server. In my case, my PPP server uses the standard Linux Bash prompt [hartr@kepler hartr]$ and requires that I type
ppp to start up PPP on the server. It is a good idea to allow for a bit of error recovery here, so in my case I use
hartr--hartr ppp
This says, if we don't receive the prompt within the timeout, send a carriage return and looks for the prompt again. Once the prompt is received, then send the string Note: don't forget to add a \ to the end of the previous line so chat still thinks the entire chat script is on one line! Unfortunately, some servers produce a very variable set of prompts! You may need to log in several times using minicom to understand what is going on and pick the stable "expect" strings. 15.5 A chat script for PAP/CHAP authenticated connectionsIf your ISP is using PAP/CHAP, then your chat script is much simpler. All your chat script needs to do is dial the telephone, wait for a connect and then let pppd handle the logging in!
#!/bin/sh
#
# This is part 2 of the ppp-on script. It will perform the connection
# protocol for the desired connection.
#
exec /usr/sbin/chat -v \
TIMEOUT 3 \
ABORT '\nBUSY\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' \rAT \
'OK-+++\c-OK' ATH0 \
TIMEOUT 30 \
OK ATDT$TELEPHONE \
CONNECT '' \
15.6 The pppd
|
_________________________________
Last Edited: Thursday, January 21, 1999 03:11 PM
Maintainer: Rob Kennedy (rob@linuxberg.com)
Site Design - Graphicjam Digital
Arts Inc. 1999.
ョ 1999 TUCOWS Interactive Ltd. All rights
reserved