"The Linux Gazette...making Linux just a little more fun!"


(?) The Answer Guy (!)


By James T. Dennis, linux-questions-only@ssc.com
LinuxCare, http://www.linuxcare.com/


(?) Automated Login Around a Challenge Card

From Wayne Xin on Thu, 20 Jan 2000

Sorry for the bold disturbance. I've been frustrated with this problem. Hope you can point me to the right solution.

I have a battery based security card that changes my password for ISP connection every minute. So I can't totally automate my login process with a fixed password. Is there a place that talks about pausing in the middle of a script for me to type in the password and then continuing to capture the remotely assigned IP?

Appreciate your help.
PS: I am talking linux 6.1 (X86) modem/ISP configuration :)

(!) In the 'expect' scripting language you can use an 'interact' function with one or more "escape patterns."
Here's an example:
#!/usr/bin/expect -f

spawn telnet  "somehost"
expect "login:"
send "myname\r"
expect "enter key from your card:"
interact "\r" {
	return
	}
expect "success"
## continue with script
interact
In this case we open a telnet to "somehost" and we automate part of the login (waiting for a login: prompt, sending a name, waiting for a sort of password for your card).
The interesting part of this is where we have the 'interact' directive. In this case we interact until an [Enter] key is entered and when we see that escape sequence we execute some 'expect' code (in this case all we're doing is executing the 'return' from the interact to the rest of our script).
It's possible in 'expect' to have multiple "escape sequences" or "macros" as options to the the 'interact' function. Each of these can have its own block of 'expect' code. These other bits of code can 'spawn' other programs that have their own nested 'interact' functions, etc.
Obviously (as I've shown) you can also have multiple 'interact' sessions in a script. (It should also be obvious that you'll only get to the second and subsequent sessions by using a 'return' from each of the preliminary 'interact' invocations.
Most 'expect' syntax is derived from the TCL libraries around which it is build. TCL is a language that was designed to be embedded into other applications and utilities and 'expect' is a utility which lets you run interactive programs, connected to psuedo-terminals and control them through its 'expect', 'send', and related functions. The rest of the language is TCL.
Anyway that's the easiest way that I know of to do this under Linux. There's also an Expect.pm PERL module. I haven't used it, but it should have most of the same features.


Copyright © 2000, James T. Dennis
Published in The Linux Gazette Issue 50 February 2000
HTML transformation by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Answer Guy Current Index ] [ Index of Past Answers ] greetings 1 2 3 5
5 6 7 8 9
10 11   13 14 15 16 17
18 19 20 21 22 23 24  
26 27 28 29 30 31 32 33
34   36 37 38 39 42 41
42 43 44 45 46 47 48


[ Table Of Contents ] [ Front Page ] [ Previous Section ] [ Linux Gazette FAQ ] [ Next Section ]