Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/Almost-same-Problem.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho