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/bashunset TELNET_USER_NAME_STRINGunset TELNET_PASSWORD_STRINGunset TELNET_USER_NAMEunset TELNET_PASSWORDTELNET_USER_NAME_STRING=`cat SAP_output`TELNET_PASSWORD_STRING="Password:"TELNET_USER_NAME="UserNam3\r"TELNET_PASSWORD="Passw0rd\r"# Expect script starts hereexpect <<- 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 eofDONE
where
SAP_output:
Trying ::1...Trying 127.0.0.1...Connected to localhost.Escape character is '^]'. *********************************************** ********************************************** ****###*******####*****#######************** **##***##****##**##****##****##************ ***##*******##****##***##****##********** *****##*****########***######*********** ******##****##****##***##************* **##***##**##******##**##************ ****###****##******##**##********** ********************************** ******************************** Telnet Administration SAP Java EE Application Server v7.50User 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: ")?