|Linux PPP HOWTO|
|Prev||Chapter 18. Automating your connections - Creating the connection scripts||Next|
A chat script is a sequence of expect string, send string pairs. In particular, note that we ALWAYS expect something before we send something.
If we are to send something WITHOUT receiving anything first, we must use an empty expect string (indicated by " ") and similarly for expecting something without sending anything! Also, if a string consists of several words, (e.g. NO CARRIER), you must quote the string so that it is seen as a single entity by chat.
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.
If the string BUSY is received, abort the operation.
ABORT '\nNO ANSWER\r'
If the string NO ANSWER is received, abort the operation
If the (repeated) string RINGING is received, abort the operation. This is because someone is ringing your phone line!
Expect nothing from the modem and send the string AT.
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!
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.
Expect OK (the modem's response to the ATH0 command) and dial the number we want to call.
Expect CONNECT (which our modem sends when the remote modem answers) and send nothing in reply.
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).
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 (man 8 chat).
Whilst 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 [ or ] (open and close square brackets).
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
and requires that I type
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
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 ppp.
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.