Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to come up with a script that will read through a list of hostnames ssh to the box then change the password obviously what I have below is not working any suggestions would be appreciated. - thanks
#!/usr/bin/perl -w use Net::SSH::Perl my $ssh = Net::SSH::Perl->new("$_"); $ssh->login("user1", "pass1"); open (IN, "<hosts.txt" ) || die "Can't open users.txt"; while(<IN>) { chomp; $ssh->cmd("passwd"); $ssh->cmd("whatever"); $ssh->cmd("whatever"); }

Replies are listed 'Best First'.
Re: Password change (Newbie)
by BUU (Prior) on Jul 01, 2003 at 18:41 UTC
    You have your constructor in the wrong place.. try this:
    #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; open IN, "<hosts.txt" or die "Can't open users.txt"; while(<IN>) { chomp; my $ssh = Net::SSH::Perl->new($_); $ssh->login("user1", "pass1"); $ssh->cmd("passwd"); $ssh->cmd("whatever"); $ssh->cmd("whatever"); }
Re: Password change (Newbie)
by jcpunk (Friar) on Jul 01, 2003 at 18:51 UTC
    I have a similar thing useing Net::Telnet, here is the code if you want it, might give you a few ideas or somethin
    sub start_login { open(STDERR, ">&STDOUT"); my $telnet; my $PASSWD = "/bin/passwd"; telnet_login($username,$password,$host,\$telnet); #custom login fu +nction $telnet->print('passwd'); $telnet->waitfor('/password:/i') or report_error("ERROR","No passw +ord prompt found");; $telnet->print($password); my($pre,$match) = $telnet->waitfor(Match => '/Incorrect password/' +, Match => '/New password:/'); $match =~ /New/ or report_error("ERROR","Not prompted for new pass +word");; $telnet->print($new_password); ($pre,$match) = $telnet->waitfor(Match => '/Bad password/', Match => '/Re-enter new password:/ +'); $match =~ /Re-enter/ or report_error("ERROR","New password rejecte +d"); $telnet->print($new_password); $telnet->waitfor('/changed/i') or report_error("ERROR","New passwo +rd rejected"); telnet_close(\$telnet); #gentially close this object, it has been +nice to us we hope $success = 1; }
    sorry but i know nothing about Net::SSH, hope this is somewhat helpful
    jcpunk
Re: Password change (Newbie)
by kutsu (Priest) on Jul 01, 2003 at 18:35 UTC

    use Net::SSH::Perl doesn't have a semicolon, don't know if that's the problem though

    "Pain is weakness leaving the body, I find myself in pain everyday" -me