Tcl Expect fails spawning SSH to server but SSH from command line works

I have some code that I'm using to connect to a server and perform some commands. The code is as follows:

#!/usr/bin/expect
log_file ./log_std.log

proc setPassword {oldPass newPass} {
    send -- "passwd\r"
    expect "* Old password:"
    send -- "$oldPass\r"
    expect "* New password:"
    send -- "$newPass\r"
    expect "* new password again:"
    send -- "$newPass\r"
}

set server [lindex $argv 0]

spawn /bin/ssh perfgen@$server

# Increase buffer size to support large text responses
match_max 100000

# Conditionally expects a prompt for host authenticity
expect {
    "*The authenticity of host*" {
        send -- "yes\r"
    }
}

What I find very strange is that when I SSH from my command line the SSH command works no problem. However, when I SSH from the shell script I get the following error:

spawn /bin/ssh perfgen@192.168.80.132

ssh: Could not resolve hostname 192.168.80.132
: Name or service not known

The same script runs against 3 servers, but 2 of the 3 servers always fail. However, if I try logging into the servers manually do do the work all three servers pass.

Any idea what might be happening here? I'm completely stumped. This code was working up until about 2 weeks ago and according to the server administrator nothing has changed on the server-side config.

Answers


Trimming any whitespace seemed to solve the issue:

set serverTrimmed [string trim $server]

Need Your Help

How to Call a WebService in titanium using javascript

javascript titanium appcelerator appcelerator-mobile titanium-mobile

I am new to titanium and and want to call a web service from my titanium app.

Modify array to have single quotes around value

php arrays

How would I modify an array in php from: