Maybe you can include all your command exchange for the first server within the block of code executed after the login prompt is successfully matched?
Something like the following:
set 11 "10.0.0.101"
set 12 "10.0.0.12"
set timeout 20
spawn telnet $11
expect {
"Unable to connect to remote host:" { }
"login:" {
send "root\r"
expect "Password:"
send "root\r"
expect "#"
send "shutdown -r now\r"
expect "#"
send "exit\r"
expect "Connection closed by foreign host."
}
}
spawn telnet $12
[...]
If after attempting to connect to $11 you get an "Unable to connect...", it will execute the empty block and move on. If it matches the "login:", it will execute all commands.
You will need to check whether your telnet closes successfully after the "Unable to connect" message (I would think it does), so that you don't end up with multiple spawned sessions.