tags:

views:

41

answers:

2

Is there a way to allow perl to initiate a telnet session and programmatically issue commands to that telnet session?

I initially tried a stupid method:

commands.pl:

sleep(1);
print $command1;
sleep(1);
print $command2;

and then

> perl commands.pl | telnet www.host.com port

This does not work.

+7  A: 

There is a Net::Telnet module.

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
                      Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;

(Example taken from that page.)

brennie
+1  A: 

One option would be through Perl's interface to Expect.

George Jempty