Rectangle 27 0

As per your code, it looks like the ssh connection got closed after the few trails of giving the passwords to ssh session.

Whenever a new process spawned with spawn command, then expect will save the spawn_id for that expect process into expect_out(spawn_id).

spawn ssh -t root@$server_address "$*"

The debug which you have seen as below.

spawn ssh -t root@10.10.10.10 sudo cat /etc/host
    root@10.10.10.10's password:
    expect: does "root@10.10.10.10's password: " (spawn_id exp4) match glob pattern "s password:"? yes
    expect: set expect_out(0,string) "s password:"
    expect: set expect_out(spawn_id) "exp4"

As you can see in the debug information, the expect_out(spawn_id) holds the spawn_id from which it has to expect for values which is exp4 in your case.

As you can see, the connection got closed after few wrong trails thereby making the process exp4 no longer exits in the context. Since the spawn_id holds the reference to the same, expect will try to expect from that process and failed.

You can refer this question to know about how this spawn_id being used with standard input (which is reading input from console)

linux - Expect script error send: Spawn id exp4 not open while executi...

linux bash shell expect
Rectangle 27 0

I have already fix it, it was an error in dos2unix command. I had to code it again over Ubuntu for avoiding to run dos2unix command.

linux - Expect script error send: spawn id exp4 not open while executi...

linux bash shell unix expect