1#!/bin/sh
2###################################################################
3#
4# Script to dial the remote system, negotiate the connection, and send
5# it the id. Then wait for the modem to disconnect. Reset the modem
6# to answer mode and wait for the system to call back.
7#
8# The telephone number and modempass are used when establishing the
9# connection to the modem.
10#
11PHONE=555-1212
12MODEMPASS=modem_identifier
13#
14# Once the modem calls back, the account name and password are used for
15# a UNIX style login operation.
16#
17ACCOUNT=my_account_name
18PASSWORD=my_password
19
20###################################################################
21#
22# Step 1. Dial the modem and negotiate the initial dialog.
23#         note: the modem is configured to ignore loss of DCD at this point.
24#         it is important that this be performed because the loss of DCD
25#         will normally prevent system from working since 'modem' is used
26#         for pppd.
27#
28#         The script is terminated normally when the carrier is lost.
29#
30chat -v							\
31	TIMEOUT		3				\
32	ABORT		'\nBUSY\r'			\
33	ABORT		'\nNO ANSWER\r'			\
34	ABORT		'\nRINGING\r\n\r\nRINGING\r'	\
35	''		AT				\
36	'OK-+++\c-OK'	'AT&C0&D2S0=0H0			\
37	TIMEOUT		30				\
38	OK		ATDT$TELEPHONE			\
39	CONNECT		''				\
40	assword:	$MODEMPASS			\
41	"\nNO CARRIER\r"
42
43if [ "$?" = "0" ]; then
44
45###################################################################
46#
47# Step 2. Wait for the call back from the remote. This will wait for at most
48#         30 seconds for the call back should the first attempt fail or
49#         something happen with the callback logic at the remote.
50#
51#         note: when the callback occurs, the DCD setting is re-enabled.
52#
53# If some voice call should happen during this period, the system will
54# answer the telephone and then hang up on them. I realize that this is
55# rude, but there is little that this script can do.
56#
57  chat -v						\
58	TIMEOUT		30				\
59	ABORT		'\nVOICE\r'			\
60	'\nRING\r'	'AT&C1A'			\
61	CONNECT		''				\
62	TIMEOUT		10				\
63	ogin:--ogin:	$ACCOUNT			\
64	TIMEOUT		45				\
65	assword:	$PASSWORD
66
67  if [ "$?" = "0" ]; then
68    exit 0
69  fi
70fi
71
72###################################################################
73#
74# The script has failed. Terminate the connection mode.
75#
76chat -v TIMEOUT 3 "" AT 'OK-+++\c-OK' 'AT&C1&D2S0=0H0' OK
77exit 1
78