You need to log in manually to know what to write for the PPP script.
To know what strings to expect, it is
a good idea to go through the login process manually, at least once. Below
is an actual screen dump of a session I had with Internet Direct. In particular,
416-233-2999. Other numbers to Internet Direct may vary in what is output
and in how you are prompted. Certainly, other ISPs will be different from
this one. minicom is usually the modem
dialer of choice if you decide to log in manually.
A Manual Login (using minicom) - Responses are in
red:
AT &F
OK
atdt*70,4162332999
CONNECT 14400/V42BIS
Welcome to Internet Direct!
If you already have a User-ID on this
system, type it in and press RETURN.
Otherwise type "new" at the login: prompt.
login: my_username
Password: XXXXXXXXX
Please wait...
Type SLIP, CSLIP, PPP
or press [ENTER] to continue: PPP
Your IP address is 207.136.100.16.
Server address is 207.136.82.56.
PPP Ready.
~y}#.!}!6}
}8}!}$}%U}"}&} } } } }%}&}$=pc}'}"}(}".Q~~y}#.!}!7} }8}!}$
The funny, unintelligible characters at the end shows that PPP is up. You can still exit minicom without hanging
up and issue the route add default gw
command using the remote IP you saw when you were in minicom. But just
leave minicom and hang up for now (using CTRL+A, X).
Let's look at the strings.
AT &F
This is a standard
string sent to the modem to tell it to reset itself to the factory-set
defaults. We need not concern ourselves wth this string,as pppd
does the settings for us.
OK
This is what the
modem responds with. It is the first thing our chat script sees. So we
should make a note of it. This tells us that all systems are "go" and we
can dial.
atdt*70,4162332999
Upon seeing the
"OK", I enter the number to dial, prefixed by "atdt", which specifies tone
dialing, as opposed to pulse dialing. The "*70," tells the phone operator
to disable call waiting, which can wreak major havoc with dialing in. This
should be standard practice for all calls you make by modem, not just the
PPP calls. You hear the modem dial, you hear the ringing, then the squelch,
then you see:
CONNECT 14400/V42BIS
Your modem is now
telling you that you have connected at the desired speed. My modem is 14.4kbps;
your mileage may vary. This is only informational, but we should still
make a note of it. It is important since it tells us that the ISP's modem
has answered before the timeout, and a connection has been made. Then we
see:
Welcome to Internet Direct!
If you already have a User-ID on this
system, type it in and press RETURN.
Otherwise type "new" at the login: prompt.
login: my_username
Obviously, when
your chat script sees the word "login", that is your next cue to respond
with a username. We ought to make note of this also. But wait ... If I
use "login:" as the expect string, you can see it appears in two places
above. It is likely that my chat script will send my username in response
to the first "login:", and by the time it sees the second, the username
will have already been received and ignored by the host. This was great
when you dialed in manually, since you do not want the host to buffer every
stray keystroke you make until the actual prompt. But now it is an impediment,
since keystrokes are not an issue with chat scripts. But this will not
impede us for long. We can also specify expect strings for the chat script
to ignore.
Password: XXXXXXXXX
Once this impediment
is overcome, the rest is easy. The word "Password:" appears once in this
session, so you can respond straight away with a password.
Please wait...
Type SLIP, CSLIP, PPP
or press [ENTER] to continue: PPP
On the prompt "or
press [ENTER] to continue:", which is
also unique, send the response "PPP" to the host.
Writing the Chat script:
So, now we have a list of 6 expect strings:
- OK
- CONNECT
- Otherwise type "new" at the login: prompt.
- login:
- Password:
- or press [ENTER] to continue:
Notice that we have
made note of both occurences of the word "login:". Also, some expect strings
are single words; others are longer.
Additional Notes:
This entire chat
script /etc/ppp/scripts/ppp-on-dialer
is all part of one, single command. It is usually put in a script file
and chopped into several lines for human readability. There is a manpage
for chat, if you want more information. Because this is a shell script,
we must put as the first line:
#!/bin/bash
The chat script
that is posted on the previous page used #!/bin/sh
(the Bourne Shell), which is really the same shell in LINUX, since they
are symbolically linked. You can use nearly any shell you like. This just
tells the kernel to invoke a subshell to run the script commands.
Now we have to give
it the command to execute:
exec chat -v \
We need the -v option
in "chat" so that detailed output can be sent to /var/log/messages
for debugging. Note the "\" on the far
right side of the line. That is a continuation mark, telling the shell
that there is more to be added to the command after the carriage return.
You must set a timeout
value for the modem to respond. 3 seconds is forever for something that
is sitting on your motherboard. Also, indent this to show that it is part
of the "chat" command.
TIMEOUT 3 \
ABORT '\nBUSY\r' \
ABORT '\nNO ANSWER\r' \
ABORT '\nRINGING\r\n\r\nRINGING\r' \
'' \rAT \
We also need to
tell the modem what to do if the chat receives an "ABORT". If we don't
get anything from the modem, test it (using "AT").
If things are fine, the modem should respond with an "OK"
'OK-+++\c-OK' ATH0 \
Depending on the
make of the modem, there are a variety of responses possible, usually involving
the string "OK", but sometimes with other characters intervening. This
was from the original PPP script that came with the downloaded ppp software.
My modem gives a simple "OK", but in case there are some weird modems out
there, it has to be compatible. Before dialing, we must make absolutely
sure the modem is hung up, so send "ATH0"
to hang it up if it is not.
TIMEOUT 45 \
Now we shall change
the timeout value of the modem for dialing in. Anything from 30 to 60 seconds
is reasonable. Any more would test your patience too much, but your mileage
may vary on that too. The modem will hang up if it takes more than 45 seconds
for the ISP to answer with this setting.
OK ATDT$TELEPHONE \
We should expect
an OK. Now we will send the number to dial. The exported shell variable
"TELEPHONE" is set in the file /etc/scripts/ppp-on
CONNECT '' \
Shows that we're
connected. If the chat script didn't see this by the timeout of 45 seconds,
it would have hung up. If the chat does see this before the timeout, then
it just sends an empty string and continues.
Other--prompt. '\r' \
This string contains
the beginning and end of the bogus "login:" string. Notice that the word
"login" and all other words between the beginning and end is left out,
and replaced with dashes to signify that there are intervening characters.
We are sending a string that contains a carriage return ("\r").
login: p$ACCOUNT \
Once we get the
real login prompt, we send the username. For some reason, on my modem the
first character is ignored. So I now give it a character followed by my
username, as set in the script ppp-on.
Password: $PASSWORD \
This is followed
by the password, which does not suffer from the same problem. On your host,
you may notice that the "login" and "Password" may be quite different.
Both may be in lowercase, upper case, initial uppercase, with or without
the colon, and so on. You have to check for these things in minicom, so
that your chat script will be appropriate. If your login and Password prompts
differ by an initial upper or initial lowercase letter, then you can place
two dashes before the words, leaving out the "L" and "P".
or--continue: ppp
And this is where
we are asked to enter the "ppp" string.
And
that is the end of the script!
Go Back
since Apr 1 2007