Other Expect stops at entering password

I use Expect to automate the interaction with some devices on telnet or ssh. For example, restarting the Wi-Fi access point when the connection is hung up, or reading incoming SMS from the GSM-gateway. Everything works perfectly.
But today I am faced with the fact that I can’t force Expect to connect to the network printer by entering a password! I do everything the same as with other devices, but my script stops at entering the password!
Here is the listing of manual interaction with the printer:
Code:
root@fw:/tmp # telnet 10.1.1.53
Trying 10.1.1.53...
Connected to 10.1.1.53.
Escape character is '^]'.

Type "help or ?" for information.
Password: <<<here I enter the password manually
_> exit
Finalizing session...

Connection closed by foreign host.
Here is my script:
Code:
#!/usr/local/bin/expect
        spawn telnet 10.1.1.53
        expect "Password: "
        send "mypassword\r"
        expect "> "
        send "exit\r"
But when I start it, the script stops after the appearance of the string "password", after which it ends on timeout:
Code:
root@fw:/tmp # ./check_printer.expect
spawn telnet 10.1.1.53
Trying 10.1.1.53...
Connected to 10.1.1.53.
Escape character is '^]'.

Type "help or ?" for information.
Password: root@fw:/tmp #
Interestingly, if after the command to send a password add "interact"
Code:
#!/usr/local/bin/expect
        spawn telnet 10.1.1.53
        expect "Password:"
        send "mypassword\r"
        interact
it turns out that the script does enter the password, but for some reason it does not send a newline character and hangs on it:
Code:
root@fw:/tmp # ./check_printer.expect
spawn telnet 10.1.1.53
Trying 10.1.1.53...
Connected to 10.1.1.53.
Escape character is '^]'.

Type "help or ?" for information.
Password: <<<here I manually press "Enter" key without entering password!
_> somecommand
Error: Invalid command. Please type "?" or "help" for more information.

_> exit
Finalizing session...

Connection closed by foreign host.

Why Expect doesn't send newline symbol? I even tried to add a newline character separately:
Code:
#!/usr/local/bin/expect
        spawn telnet 10.1.1.53
        expect "Password: "
        send "mypassword\r"
        send "\n"
        expect "> "
        send "exit\r"
I also tried to remove the space at the end of the expected lines:
Code:
#!/usr/local/bin/expect
        spawn telnet 10.1.1.53
        expect "Password:"
        send "mypassword\r"
        expect ">"
        send "exit\r"
Nothing helps!
 
Back
Top