hi,
skin sent me a private email about this thread, and some of his code. i won’t post his code, but thought that the reply might be useful. Expect is kind of a cool scripting language to know–and not just for AppleScripting.
hi skin,
sorry it took so long to reply, i usually don’t check these things.
yes. it’s also available on Linux and most Unix distributions.
don’t worry. if you can use AppleScript to script something like the Terminal, then you can do Expect. you will probably find it really easy.
ok. first, i should probably explain everything that i’m doing. first, i figure out what to ‘expect’. i know that Telnet will try to authenticate as my user if i don’t give it a ‘-K’ flag. so i do that:
telnet xxx.xxx.xxx.xxx -K
and i get:
login:
so i know that will be what to ‘expect’. so already i know that i can write an Expect script like this:
#!/usr/bin/expect
spawn /usr/bin/telnet -K xxx.xxx.xxx.xxx
set user “me”
expect “login:”
send “$user”
i save this as an executable script. say i call it expectTelnet.
now when i run that at the command line, expect spawns a telnet session under itself and waits for what i told it to look for. when it sees, “login:”, it will send my username. nice, huh?
but that’s not good enough. i need to specify my telnet server, and i may need to use a different username. no problem, i just use command line arguments, like this:
#!/usr/bin/expect
spawn /usr/bin/telnet -K [lindex $argv 0]
set user [lindex $argv 1]
expect “login:”
send “$user”
now i save that as an executable and run it like this:
./expectTelnet xxx.xxx.xxx.xxx me
as you can see, as long as i know what to ‘expect’ next i can pretty much write the whole session.
now i wrap that in an AppleScript so that it has a GUI. i ask the user for the info that i want with some display dialogs & variables (i’m sure you understand this part, so i won’t bother explaining that). then i write the expect file to the ‘/tmp’ directory and call it with my arguments.
as you can see it works pretty well. you should read the wikipedia article i attached, which explains a lot.
i’m going to post this as a reply to our earlier thread. i won’t include your code, but i think the discussion may be useful to someone–cheers.