Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Folks:
I am trying to write a script to telnet a service on local service but I really don't know how to do it.
Basically, there are two tasks:task 1 is to get connection with the service:
"telnet localhost 1300" where 1300 is the port the service listens on.After get connection with the service I then need to do task2.
task2 is to execute a command and forward the result to a file:
"subnet 1.2.3.4 > output.txt"I did some research about it and it seems expect command does that kind of work. Howerver, please notice that I don't need user name/ password or a remote host in order to connect to the port.
Can anybody give me some clue?
Thanks a lot!!!
gangchen

rsh is often used to execute something on a remote machine. You can't use it for non-standard ports, though.
The expect syntax looks like this:
spawn "/bin/sh"
send "telnet localhost 1300\r"
sleep 1
expect "some_prompt"
send "subnet 1.2.3.4 > output.txt\r\r"
close

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |