Книга: Linux Network Administrator Guide, Second Edition
A Sample Script
A Sample Script
Assume that the host to which we make our SLIP connection is cowslip, and that we have written a script for dip to run called cowslip.dip that makes our connection. We invoke dip with the script name as argument:
#
dip cowslip.dip
DIP: Dialup IP Protocol Driver version 3.3.7 (12/13/93)
Written by Fred N. van Kempen, MicroWalt Corporation.
connected to cowslip.moo.com with addr 192.168.5.74
#
The script itself is shown in Example 7.1.
Example 7.1: A Sample dip Script
# Sample dip script for dialing up cowslip
# Set local and remote name and address
get $local vlager-slip
get $remote cowslip
port ttyS3 # choose a serial port speed
38400 # set speed to max
modem HAYES # set modem type
reset # reset modem and tty
flush # flush out modem response
# Prepare for dialing.
send ATQ0V1E1X1r
wait OK 2
if $errlvl != 0 goto error
dial 41988
if $errlvl != 0 goto error
wait CONNECT 60
if $errlvl != 0 goto error
# Okay, we're connected now
sleep 3
send rnrn
wait ogin: 10
if $errlvl != 0 goto error
send Svlagern
wait ssword: 5
if $errlvl != 0 goto error
send knockknockn
wait running 30
if $errlvl != 0 goto error
# We have logged in, and the remote side is firing up SLIP.
print Connected to $remote with address $rmtip
default # Make this link our default route
mode SLIP # We go to SLIP mode, too
# fall through in case of error
error:
print SLIP to $remote failed.
After connecting to cowslip and enabling SLIP, dip will detach from the terminal and go to the background. You can then start using the normal networking services on the SLIP link. To terminate the connection, simply invoke dip with the -k option. This sends a hangup signal to dip, using the process ID dip records in /etc/dip.pid:
#
dip -k
In dip 's scripting language, keywords prefixed with a dollar symbol denote variable names. dip has a predefined set of variables, which will be listed below. $remote and $local, for instance, contain the hostnames of the remote and local hosts involved in the SLIP link.
The first two statements in the sample script are get commands, which is dip 's way to set a variable. Here, the local and remote hostnames are set to vlager and cowslip, respectively.
The next five statements set up the terminal line and the modem. reset sends a reset string to the modem. The next statement flushes out the modem response so that the login chat in the next few lines works properly. This chat is pretty straightforward: it simply dials 41988, the phone number of cowslip, and logs in to the account Svlager using the password knockknock. The wait command makes dip wait for the string given as its first argument; the number given as its second argument makes the wait time out after that many seconds if no such string is received. The if commands interspersed in the login procedure check that no error occurred while executing the command.
The final commands executed after logging in are default, which makes the SLIP link the default route to all hosts, and mode, which enables SLIP mode on the line and configures the interface and routing table for you.
- Appendix J. Example scripts code-base
- Two Example sendmail.mc Files
- Chapter 17 Developing ASP.NET Web Applications
- Chapter 9 Generics
- Chapter 13 Arrays and Collections
- Appendix A C# Keywords
- Appendix C Generating Documentation for Your C# Applications
- Language Syntax
- random_shuffle
- Overriding the Power State Configuration for Device Classes
- Exporting Stream Functions
- Chapter 12. Debugging your scripts