Wayne I
unread,Jan 30, 2012, 6:40:33 AM1/30/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi,
The man page of expect says "the following statement could be used to autologout users who have not typed anything for an hour but who still get frequent system messages: "
interact -input $user_spawn_id timeout 3600 return -output \
$spawn_id
This describes exactly what I want to do with our ERP system as users who walk away and leave their terminal logged in overnight cause file locks and other problems. But after 2 days of reading and hours of expermentation I can't get this to work. I must admit I still don't have my head around some of the most basic concepts so please excuse me in advance for asking any dumb questions.
1. I have send and expect pairs on separate lines which work for a couple of commands but then one of the expects won't pickup the string I am searching for. But it's there, I can see it, I even generated the original script with autoexpect and cut it down to just match the prompt. Why is it not matching?
2. I have a set timeout 10 so after a while the script carries on and executes the interact command shown above (except I changed the timeout value to 15), but I don't get any output. It's like stdout has been redirected to /dev/null or something. But I seem to be able to "blindly" step through a couple of menu options okay. If I then wait the interact timeout terminates the script. Why don't I get any output?
3. Despite having read the man page I can't understand what the -input and -output options are doing in the interact command, as well as the associated $user_spawn_id and $spawn_id. I haven't been able to find any other examples on the web of interact commands that use them. And even though I can guess the "return" option means its "stopping", to what degree? Does it stop interacting and carry on with the script or terminate the script entirely and return to a command prompt?
4. The whole point of this exercise is to exit "gracefully" from the ERP system. Conveniently this can be done by simulating the user typing the word "end" and pressing return enough times, but partly because of my other problems I'm not sure how to get the syntax correct for doing this with the above interact command.
My script is below.
Thanks
Wayne
-------
set force_conservative 1 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout 10
spawn $env(SHELL)
match_max 100000
expect -exact "# "
send -- "su - test\r"
expect -regexp "Power Windows"
send -- "N\r"
expect -regexp "Choose a number from above"
send -- "9"
send -- "\r"
sleep 1
send_user "going into interact mode"
interact -input $user_spawn_id timeout 16 return -output $spawn_id
send_user "leaving interact mode"