Net-Appliance-Session - 2 new Function for Module

Posted on Sat Jan 26 05:35:24 2008 by onishin
2 new Function for Module
Hello, I have code 2 new function . I use module Net-Appliance-Session for backup config all cisco in my society . And I need to rebound from cisco at cisco . That's why I needed to make the two functions I have coded the best for me (they work well) , I be sure they can optimise or be a function for other user
sub byssh { my $self = shift; my %args = @_; $args{Opts} = '' if !exists $args{Opts}; $args{App} = 'ssh' if !exists $args{App}; if (!defined $args{Password}) { raise_error "'Password' is a required parameter to telnet connect" . "when using active login"; } if (! defined $args{Host}) { raise_error 'Cannot log in to an unspecified host!'; } if (exists $args{Port}) { $args{Opts} .= ' -p ' . $args{Port} ; } if (exists $args{Name}) { $args{Opts} .= ' -l ' . $args{Name} ; } my $string = $args{App} . " " . $args{Opts} . " " . $args{Host} ; $self->print($string) ; my $match; $self->waitfor($self->pb->fetch('pass_prompt')) or $self->error('Failed to get privileged password prompt'); $self->print($args{Password}); $self->waitfor($self->prompt) or $self->error('Login failed to remote host'); return $self; } sub bytelnet { my $self = shift; my %args = @_; $args{Opts} = '' if !exists $args{Opts}; $args{App} = 'telnet' if !exists $args{App}; if (!defined $args{Password}) { raise_error "'Password' is a required parameter to telnet connect" . "when using active login"; } if (! defined $args{Host}) { raise_error 'Cannot log in to an unspecified host!'; } if ( defined $args{Port} ) { $args{Opts} .= ' ' . $args{Port} ; } my $string = $args{App} . " " . $args{Host} . " " . $args{Opts} ; print "$string\n"; $self->print($string) ; my $match; (undef, $match) = $self->waitfor($self->pb->fetch('userpass_prompt')) or $self->error('Failed to get first prompt'); if ($match =~ eval 'qr'. $self->pb->fetch('user_prompt')) { # delayed check, only at this point do we know if Name was required if (! defined $args{Name}) { raise_error "'Name' is a required parameter to Telnet connect " . "when connecting to this host"; } $self->print($args{Name}); $self->waitfor($self->pb->fetch('pass_prompt')) or $self->error('Failed to get password prompt'); } $self->print($args{Password}); $self->waitfor($self->prompt) or $self->error('Login failed to remote host'); $self->cmd("terminal length 0") ; return $self; }
Direct Responses: 6956 | Write a response