in reply to Perl and Telnet
. BTW, how are you doing the telnet? are you using the command 'telnet" or using a module? I would recommend Net::Telnet
-SK
update: Here is a code snippet using Net::Telnet
#!/usr/bin/perl -w use Net::Telnet; my $telnet; # Your prompt setting might be different $telnet = new Net::Telnet ( Timeout => 10, Errmode => 'die', Prompt => + '/.*%/'); $telnet->open('YOUR HOSTNAME'); # Enter your host name here print ("Please enter Username: "); $user = <STDIN>; print ("Please enter password: "); $pass = <STDIN>; $telnet->login($user, $pass); # You can hard code user/pass but here i + am getting getting user input to avoid typing them in. print ($telnet->cmd('date')); # Run a command then print out the resul +t
You can put this entire block until execution into a package/sub. Then whenever you want to execute a command you can just use the telnet object that was created.
(assuming your return it back to the caller)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl and Telnet
by Leviathan7z (Initiate) on Jul 28, 2005 at 03:23 UTC | |
by sk (Curate) on Jul 30, 2005 at 17:55 UTC |