Computing.Net > Forums > Unix > A script to telnet a service

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

A script to telnet a service

Reply to Message Icon

Name: G Chen
Date: October 29, 2004 at 11:13:48 Pacific
OS: Debian
CPU/Ram: AMD/256MB
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: October 29, 2004 at 12:18:21 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: A script to telnet a service

Script to auto login to telnet session www.computing.net/answers/unix/script-to-auto-login-to-telnet-session/2854.html

Script to insert lines in a file www.computing.net/answers/unix/script-to-insert-lines-in-a-file/4992.html

shell script to get value of field www.computing.net/answers/unix/shell-script-to-get-value-of-field/6716.html