How do you use if/then/else statements within an expect script in Linux?
Question by I Drive Cab: How do you use if/then/else statements within an expect script in Linux?
I am writing an expect script to test usernames on a remote mail server and I need to make the ending either fit the expected result, echo as such and exit, or find out it’s bad, echo as such and exit. My script as of right now is as follows:
–BEGIN CODE–
#!/usr/bin/expect -f
log_user 1
set VARNAME [lindex $ argv 0]
spawn telnet mymailserver.blah 25
expect “220 mymailserver.blah”
send — “ehlo 1.2.3\r”
expect “250 HELP”
send — “mail from: [email protected]\r”
expect “250 2.1.0 [email protected]… Sender ok”
send — “rcpt to: $ VARNAME\r”
if {
expect “Recipient ok”
}
{spawn echo “$ VARNAME matches!”}
else {spawn exit 1}
send “quit\r”;
–END CODE–
My if keeps killing the script. Output as follows:
syntax error in expression ”
expect “Recipient ok”
“: variable references require preceding $
while executing
“if {
expect “Recipient ok”
}”
(file “./tt” line BLAH)
Any help from you gurus out there would be highly appreciated.
Thanks!
Best answer:
Answer by Chad
IDK
Add your own answer in the comments!