I'm using a bash script to log into a telnet server and execute a number of commands. It looks like:
login_and_run.sh
#!/bin/bash
unset TELNET_USER_NAME_STRING
unset TELNET_PASSWORD_STRING
unset TELNET_USER_NAME
unset TELNET_PASSWORD
TELNET_USER_NAME_STRING=`cat SAP_output`
TELNET_PASSWORD_STRING="Password:"
TELNET_USER_NAME="UserNam3\r"
TELNET_PASSWORD="Passw0rd\r"
# Expect script starts here
expect <<- DONE
spawn telnet localhost 50008
expect '$TELNET_USER_NAME_STRING'
send "$TELNET_USER_NAME"
sleep 3
expect "$TELNET_PASSWORD_STRING"
send "$TELNET_PASSWORD"
sleep 3
spawn ls
expect eof
DONE
where
SAP_output:
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
***********************************************
**********************************************
****###*******####*****#######**************
**##***##****##**##****##****##************
***##*******##****##***##****##**********
*****##*****########***######***********
******##****##****##***##*************
**##***##**##******##**##************
****###****##******##**##**********
**********************************
********************************
Telnet Administration
SAP Java EE Application Server v7.50
User name:
telnet logs in, I get the banner, but it stops there (as if the strings are not matching). Would it be safer to use wildcards instead of the exact response (and match only " User name: ")?
\r\nfor newlines, and that file, I'm guessing, does not contain carriage returns.exp_internal 1-- that will show you when your patterns are not matching.