| |||||||||||
Almost same Problem Posted by pmnf (pmnf), 26 July 2004 I it's me again. my problem is a little bit strange now i have this script runing great in some machines, in fact only one but in others ...... it only works sometimes #!/usr/bin/expect -- # #initialize variables set ARGUMENTOS [ split $argv " " ] set NUM_ARG [ llength $ARGUMENTOS ] set USER [ lindex $ARGUMENTOS 0 ] set PASSWD [ lindex $ARGUMENTOS 1 ] set SITE [ lindex $ARGUMENTOS 2 ] set LOG_USER [ lindex $ARGUMENTOS 3 ] log_user $LOG_USER if { $NUM_ARG < 4 } then { puts "usage: $argv0 <login> <passwd> <site> <log_user [0|1]>" exit } spawn telnet $SITE expect { "login:" { send "$USER\r" } } expect { "*Password:" { send "$PASSWD\r" send "\n" send "cd nagios ;" expect { "bash" { send "./extract.sh\r" #puts "DOING EXTRACT" expect bash } } } } expect "bash" puts $expect_out(buffer) # end # My problem is that in some machines i always get the output of the extract.sh But in other machines sometimes it dosent work I run the script 100 times and i got 30% sucesses in my trouble machine Thanks Posted by admin (Graham Ellis), 26 July 2004 Usual problems with this sort of problem are timing issues such as turn around delays; having got a response from an expect you may want to wait a moment before you do your next send.You don't say describe how it doesn't work .... does it hang up for a while then return nothing, .... does it hang up and never come back .... does it simply give you the wrong results .... does it give you some form of error message? Thinking about HOW if fails may be a further clue to WHY it fails. Also think about the machine that always works. Is it nearby on your LAN, or distant? If it's distant, or if it has a very fast processor compared to the others, then there's a clue that your problem is turnround related. Posted by pmnf (pmnf), 27 July 2004 Both machines are in the same Lan, they both are Aix machines and one has 4 processor the other as 1.The machine that dosent always work is the one with one processor. As previous i whant to get the result of the extract.sh script sometimes the result get's printed by the expect_out(buffer) sometimes expect_out(buffer) as only the login message, delivered by telnet to every user that logins. Posted by admin (Graham Ellis), 27 July 2004 Then I'm going to suggest its the turn-around delay ... that the one processor machine prompts for your password but thinks it has a few milliseconds to wait before you actually respond, not thinking its talking to an automaton. Have you tried a delay before you send the password, or sending it slowly?Posted by pmnf (pmnf), 27 July 2004 Yes i'have tried that. I used in a more recent version set send_human {.1 .3 1 .05 2} and set send_human {.2 .3 .1 .1 3} i also issued a sleep before the password. ( sleep 1 ) i will now increase the value Posted by pmnf (pmnf), 27 July 2004 it was true no thinking is a problem. i've discoverd the solutions/problem The thing is that the output of the extract.sh is at the same time the input of the expect. So while there is output of the extract.sh != bash keep running #!/usr/bin/expect # spawn telnet ptibm14.telecom.pt log_user 0 set V 0 expect { "login:" { send "USER\r" expect "*assword:" { send "PASSWORD\r" sleep 1 send "\n" expect "bash" { send "cd nagios;./extract.sh\n" while { $V < 1} { expect "bash" { set V 1 } } puts $expect_out(buffer) } } } } # end # this works thanks Posted by admin (Graham Ellis), 27 July 2004 Glad you have it sorted - yes, you do have to think differently with Expect since you have parallel processes.This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |