Question

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.

Was it helpful?

Solution

Trimming any whitespace seemed to solve the issue:

set serverTrimmed [string trim $server]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top