×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

telnet package

telnet package

telnet package

(OP)
Hi,

I am trying to write  a script that simple executes a command on the telnet to a host and port and saves a 'result.txt' in the same directory.
-------------
Example:
-------------
test>telnet test.host.com 9999
Trying ..
Connected to test.host.com
Escape Character '^]'.
<command to execute>
{should output results}
-------------
This works fine showing results when tried to telnet and execute a command. I have a list of commands in a text file I like to execute when connected to a <host & port> on telnet.

Need help as to what packages to use and how. I have never tried this type before, but would appreciate if an expert can help.


balji9
{preethib@yahoo.com}

RE: telnet package

You can find a module that will help at http://www.cpan.org/modules/by-module/Net/.

Net-Telnet-3.02.tar.gz

If you don't want to use the module, you can simply open a pipe to 'telnet', connect to the other system, and print your commands through the pipe.  Here is an example of doing that with ftp...


# Set the default values.
$cmd       = "ftp -n";  # change "ftp -n" to "cat -n" for testing.

$template  =
"      open $remote_host
       user anonymous guest\@$localhost
       ascii
       lcd \"$config_dir\"
       cd $remote_dir
       get $dblist_file
       bye
";
print $template;

# Run the batch ftp command.
print(STDERR "      Running command ($cmd).\n");
open(CMD, "|$cmd") || die("Could not start command ($cmd). $!\n");
print CMD $template;
close(CMD);


I would suggest figuring out the module.  It has been my experience that most available module on CPAN will save a lot of work in the long run.

'hope this helps...

 
 
 
 keep the rudder amid ship and beware the odd typo

RE: telnet package

(OP)
Hi Goboating programmer,

Thanks for the reply. I am a bit confused on using login information. Since when I try to run the command on telnet I don't enter any login/passwd information. As mentioned before, I type in the command just after the line

'Connected to test.host.com
Escape Character '^]'.'

Does this mean by default I am using the same login profile of the system to telnet.



balji9

RE: telnet package

hello balji9,
I'm sorry I don't have time to get into this right now.  I did, however, find a decent reference for using the Net::Telnet module on activestate.com at http://velocity.activestate.com/docs/ActivePerl/site/lib/Net/Telnet.html.

That module is available for Linux, Solaris, and Windows from www.cpan.org or for the WinOS's from activestate using their PPM utility.  Sorry I can't be of more use immediately.  I have not worked with this module before and don't have the time to do any digging.

'hope this helps.

 
 
 
 keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close