> Hi,
>   I have written a web based utility that requires to login to several
> machines and do some routine tasks
> MY script uses Net::Telnet and works fine on most machines
> I use the the login() method to login to the servers
> 
> The problem comes when the server sometimes has a different prompt
> password like
> 
> login: ram
> Password for ram:
> 
> Instead of just "password:" . I can get over this by using waitfor() and
> print() but the solution is patchy, because I have to write a seperate
> procedure for some hosts.
> 
> Can I change login() or write my own generic login()  that would work on
> all hosts
> 

Ah, the beauty of Perl and OOP in general.  You should be able to
subclass Net::Telnet, then just supply your own 'login' method. This
should be relatively trivial.  Create a module, 

Net::Telnet::Ram

Or something similar, and have it inherit from Net::Telnet

package Net::Telnet::Ram;
use Net::Telnet;
our @ISA qw(Net::Telnet);

And provide your own login method,

sub login { ... }

Then when you instantiate your object in your script just switch the
call to use the subclass,

use Net::Telnet::Ram;
my $connect = new Net::Telnet::Ram ( ... );

Pretty much everything else is the same. 

The tricky part is going to be what to do with 'login' above. Probably
you will need to copy and paste most of the code from the original
login, and make your adjustments where you need them.  You have the
option of calling SUPER::login within your module's 'login' but in this
case I don't think it will be appropriate.  Obviously in the future you
will need to pay particular attention to changes in that method if/when
you upgrade Net::Telnet to make sure any bugs fixed in 'login' are also
fixed in your version, as presumably they will have been copied. 

Alternatively you could just hack your version of the module, but to me
this is more of a maintenance nightmare than subclassing it.

Check out perldoc for specifics related to module creation, oop, etc.
the above lines of code may not be complete.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to