Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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]>"
spawn telnet $SITE

       expect {
               "login:" {
                       send "$USER\r"
expect {
               "*Password:" {
                       send "$PASSWD\r"
                       send "\n"
                       send  "cd nagios ;"
                       expect {
                               "bash" {
                                       send "./\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

But in other machines sometimes it dosent work
I run the script 100 times and i got 30% sucesses in my trouble machine


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 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 is at the same time the input of the expect. So while there is output of the
!= bash keep running


spawn telnet
log_user 0
set V 0
expect {
                       send "USER\r"
                       expect "*assword:" {
                                       send "PASSWORD\r"
                                       sleep 1
                                       send "\n"
                                       expect "bash" {
                                                       send "cd nagios;./\n"
                                                       while { $V < 1} {
                                                       expect "bash" {
                                                               set V 1
                                                               puts $expect_out(buffer)

# end #

this works

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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

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