Itβs hard to say, but from the output, it looks like this:
- Your script does not wait for registration to complete before sending the next command.
- Your script terminates and closes the process before you can see any output.
There are no guarantees in life, but I would try this as a first step:
#!/usr/bin/expect -f spawn telnet 10.62.136.252 expect "foobox login:" send "foo1\r" expect "Password:" send "foo2\r" # Wait for a prompt. Adjust as needed to match the expected prompt. expect "justin>" send "echo HELLO WORLD\r" # Wait 5 seconds before exiting script and closing all processes. sleep 5
Alternatives
If you can't get your script to work by manually programming it, try auto-sensing the script that comes with Expect. You can execute your commands manually, and autoexpect will generate Expect typescript based on these commands, which can then be edited if necessary.
This is a good way to find out what Expect actually sees, especially when the problem is difficult to identify. This will save me a lot of debugging time over the years, and it is definitely worth a try if the above solution does not work for you.
source share