Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub connectSSH{
- my $user = "...";
- my $password = "...";
- my $ssh2 = Net::SSH2->new();
- my $chan;
- if($ssh2->connect($ip,$port,Timeout => 10)){
- if(!$ssh2->auth_password($user, $password)){
- print"Error: Password wrongn";
- exit;
- }else{
- $chan = $ssh2->channel(); # SSH
- $chan->blocking(0);
- $chan->shell();
- }
- }else{
- print "Connection to $ip not possiblen";
- exit;
- }
- return $chan;
- }
- sub sendCommand{
- my ($chan,$command) = @_;
- my @output=();
- print $chan "$commandn";
- #usleep(500)
- push(@output,"$_") while <$chan>;
- #process output...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement