General
cancel
Showing results for 
Search instead for 
Did you mean: 

Troubleshooting script that uses expect

Andrew Kaplan
Super Advisor

Troubleshooting script that uses expect

Hi there --

I am writing a script that is designed to automate the interactive responses that are user would enter to gain access to a remote server. I have expect installed on the local workstation, which in this case is a Fedora Core 2 system.

The script consists of two parts. The first part references the expect file in question, while the second part is the expect file. Listed below are the two files:

tps_expect script:

Code:

#!/bin/bash

# This script will provide access to the tcs application which
# is located on the remote server.

# First disable access control so that only the tps server can connect
# to this client.
xhost +

# Establish a telnet session with mcrs1. NOTE: The address in question is
# the address that mcrs1 has on the Partners network, and not the internal
# tcs network address. The syntax shown below is designed to prompt the
# operator for the appropriate username and password.

expect start_pts.expect

start_pts.expect script:

Code:

#!/bin/tcsh

# This script runs in conjunction with the tps_expect script.
# It uses the expect utility to automate several interactive
# commands the user would normally enter.

spawn telnet mcrs1
expect {
login: {tps
send "username\n"
}
}
expect {
Password: {tps
send "mypassword\n"
}
}
expect {
"$ " {
send setenv DIPSLAY :0.0\n"
}
}
expect {
"$ " {
send "exec cd /TCS_MGH/TPRRuntime/\n"
}
}
expect {
"$ " {
send "exec startTPR.pl\n"
}
}

When I run the tps_expect script, here is the output that I encounter:

Quote:
being added to access control list
spawn telnet
Trying ...
Connected to .
Escape character is '^]'.

HP-UX B.10.20 E 9000/785 (ttyp3)

login: invalid command name "tps"
while executing
"tps"
invoked from within
"expect -nobrace login: {tps
send "username\n"
}"
invoked from within
"expect {
login: {tps
send "username\n"
}
}"
(file "start_pts.expect" line 8)
Can someone help me correct the syntax errors in question? Thanks
A Journey In The Quest Of Knowledge