Leser: 5
|< 1 2 >| | 17 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
use strict;
use warnings;
use Net::SSH qw(ssh issh sshopen2);
my $command="passwd USERNAME";
issh('USERNAME@HOSTNAME', $command);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH qw(ssh issh sshopen2);
my $user = "USERNAME";
my $host = "HOSTNAME";
my $cmd = "passwd USERNAME";
sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
while (<READER>) {
chomp();
print "$_\n";
}
close(READER);
close(WRITER);
ssh USER@SOLARISHOST passwd
ssh -t USER@SOLARISHOST passwd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Math::BigInt::GMP; use Term::ReadKey; my $host = "IPADRESSE"; my $username = "USERNAME"; my $old_password = "PASSWORD_ALT"; my $new_password = "PASSWORD_NEU"; my $ssh = Net::SSH::Perl->new( $host, debug => 1, protocol => '2', #use_pty => 1, #interactive => 1, options => ["UsePrivilegedPort no"]); $ssh->login($username, $old_password); # Testen welches OS my ($stdout, $stderr, $exit) = $ssh->cmd('uname'); chomp $stdout; if ( $stdout eq "SunOS") { &solaris; } else { &linux; } print "Betriebssystem: $stdout \n"; sub solaris { $ssh->register_handler("stderr", sub { my($channel, $buffer) = @_; my $str = $buffer->bytes; print "STRING $str\n"; if ($str eq "Enter existing login password:") { print "Enter exisiting \n"; $channel->send_data($old_password); } elsif ($str eq "New Password:") { print "New \n"; $channel->send_data($new_password); } elsif ($str eq "Re-enter new Password:") { print "New again \n"; $channel->send_data($new_password); } }); } sub linux { $ssh->register_handler("stderr", sub { my($channel, $buffer) = @_; my $str = $buffer->bytes; print "STRING $str \n"; if ($str eq "(current) UNIX password: ") { $channel->send_data($old_password); } elsif ($str eq "Enter new password: ") { $channel->send_data($new_password); } elsif ($str eq "Re-type new password: ") { $channel->send_data($new_password); } }); } $ssh->cmd('passwd');
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/perl use warnings; use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my $user = $ARGV[0]; my $password_old = $ARGV[1]; my $password_new = $ARGV[2]; my $host = $ARGV[3]; use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "$host", user => "$user", password => "$password_old", raw_pty => 1, ); my $login_output = $ssh->login(); $ssh->exec("stty raw -echo"); $ssh->send("passwd"); $ssh->waitfor('password:\s*\z', 1) or die "prompt 'password' not found after 1 second"; $ssh->send("$password_old"); $ssh->waitfor(':\s*\z', 1) or die "prompt 'New password:' not found"; $ssh->send("$password_new"); $ssh->waitfor(':\s*\z', 1) or die "prompt 'Confirm new password:' not found"; $ssh->send("$password_new"); my ($before_match, $match) = $ssh->waitfor('>\s*\z', 1); # waitfor() in a list context
|< 1 2 >| | 17 Einträge, 2 Seiten |