expect the unexpected!
I do hate it when people say that, because ....
But since I am not a total pedant and only have 9/10 for getting side tracked I am posting to ask if anyone knows why my expect script does not work. It apears to log on ok to my remote linux box, but fails to execute anything. I am planning to launch grip, xterm's and the like as I dont have enough monitors, keyboards, space for them or arms as long as my network cabels.
Anyway the scripts is like this
---------------CUT here--------------------------------
#!/usr/bin/expect --
# # In this program, we telnet to a host, execute two commands, # and leave.
# prevent an untimely end. If you have a command that takes a # time, adjust this set timeout 5000
# We start a telnet session............................. spawn telnet 192.168.0.97
# A telnet session begins with a login prompt, so we 'expect' # one here, and send the username in response. # The \r represents a carriage return. Everytime you would press # <Enter> # interactively, send a \r.
expect "login: " send "oms101\r"
# We then send the password, note thats not my password expect "assword: " send "mylittlelinuxbox\r" send "xterm &\r"
# We know in advance what our command prompt is, and we # 'expect' it accordingly. If we get it, we send the # 'mkdir test' and press enter (\r) expect " >" send "mkdir test\r"
exit
---------------CUT here--------------------------------
maybe it is time to learn python! anyway some background here is a screen scrape from the execution of the script
---------------CUT here--------------------------------
fred_grip
spawn telnet 192.168.0.97 Trying 192.168.0.97... Connected to 192.168.0.97. Escape character is '^]'. Welcome to SuSE Linux 7.0 (i386) - Kernel 2.2.16 (2).
ford login: oms101 Password: Last login: Wed Mar 28 10:00:24 from charly.local Have a lot of fun... oms101@ford:~ > >
---------------CUT here--------------------------------
and here is what happens when I telnet in and ls the root directory unfortunately no sign of my new test directory, whats going on?
---------------CUT here--------------------------------
oms101@ford:~ > ls mp3 nsmail wav oms101@ford:~ >
---------------CUT here--------------------------------
Chears
Owen
Date: 30-Jul-01 Time: 19:47:52
On Mon, 30 Jul 2001 oms101@freeuk.com wrote:
# We then send the password, note thats not my password expect "assword: " send "mylittlelinuxbox\r" send "xterm &\r"
Is xterm actually going to execute? I am guessing you will need to export the DISPLAY varible to an X-server that will allow the connection etc. If all this is already setup etc. and working then I don't have a clue as I have never used expect....
Adam
On 30-Jul-01 Adam Bower wrote:
On Mon, 30 Jul 2001 oms101@freeuk.com wrote:
# We then send the password, note thats not my password expect "assword: " send "mylittlelinuxbox\r" send "xterm &\r"
Is xterm actually going to execute? I am guessing you will need to export the DISPLAY varible to an X-server that will allow the connection etc. If all this is already setup etc. and working then I don't have a clue as I have never used expect....
If the box can find your machine by name (eg charly.local in my case in the hosts file[ dont have dns as no fixed server yet]) then xterms will be sent to the appropriate maschine in SuSE (Not sure if this is there setup magic or standard, but it works for me in telnet) with no other setting up.
No I am not getting any commands being sent to the other box
Owen
The answer was given to me by Alexis Lee thanks
Anyway the scripts is like this
---------------CUT here--------------------------------
#!/usr/bin/expect --
should be -f at the end of this line not --
# # In this program, we telnet to a host, execute two commands, # and leave.
# prevent an untimely end. If you have a command that takes a # time, adjust this set timeout 5000
# We start a telnet session............................. spawn telnet 192.168.0.97
# A telnet session begins with a login prompt, so we 'expect' # one here, and send the username in response. # The \r represents a carriage return. Everytime you would press # <Enter> # interactively, send a \r.
expect "login: " send "oms101\r"
# We then send the password, note thats not my password expect "assword: " send "mylittlelinuxbox\r" send "xterm &\r"
now here the xterm & executes to fast so after the password is entered I put in a
sleep 1
and a useful command I did not know about called
interact
bet you can guess what it does.
unfortunately the script finishes so fast that the xterm & does not work but xterm does so I just changed it to xterm
Thanks
Owen Synge
# We know in advance what our command prompt is, and we # 'expect' it accordingly. If we get it, we send the # 'mkdir test' and press enter (\r) expect " >" send "mkdir test\r"
exit
---------------CUT here--------------------------------
maybe it is time to learn python! anyway some background here is a screen scrape from the execution of the script
---------------CUT here--------------------------------
fred_grip
spawn telnet 192.168.0.97 Trying 192.168.0.97... Connected to 192.168.0.97. Escape character is '^]'. Welcome to SuSE Linux 7.0 (i386) - Kernel 2.2.16 (2).
ford login: oms101 Password: Last login: Wed Mar 28 10:00:24 from charly.local Have a lot of fun... oms101@ford:~ > >
---------------CUT here--------------------------------
and here is what happens when I telnet in and ls the root directory unfortunately no sign of my new test directory, whats going on?
---------------CUT here--------------------------------
oms101@ford:~ > ls mp3 nsmail wav oms101@ford:~ >
---------------CUT here--------------------------------
Chears
Owen
Date: 30-Jul-01 Time: 19:47:52
alug, the Anglian Linux User Group list Send list replies to alug@stu.uea.ac.uk http://www.anglian.lug.org.uk/ http://rabbit.stu.uea.ac.uk/cgi-bin/listinfo/alug See the website for instructions on digest or unsub!
Date: 01-Aug-01 Time: 01:06:32