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

Perl Monks, I am trying to use user input for username and password. Then run password to change the current password. I seem to having issues passing the input the first time. If I put the username and password in the script it works but soon as I put the variables I get the error on line 34. Here is my code and here are the errors as well. Thank you in advance.


#!/usr/bin/perl use strict; use warnings; use Net::SSH::Expect; print "Enter your username: "; my $unme =<>; print "Enter current passwd: "; system('stty','-echo'); chop(my $cur_pswd =<STDIN>); system('stty','echo'); print "\n", "Enter new passwd: "; system('stty','-echo'); chop(my $new_pswd =<STDIN>); system('stty','echo'); print "\n", "Enter new passwd again: "; system('stty','-echo'); chop(my $val_pswd =<STDIN>); system('stty','echo'); print"\n"; if ($new_pswd eq $val_pswd){ my $ssh = Net::SSH::Expect->new( host => 'localhost', user => "$unme", password => "$cur_pswd", raw_pty => 1 ); warn "Starting SSH... \n"; $ssh->run_ssh(); warn "Testing login output... \n"; my $login_output = $ssh->login(); print " Done", "\n"; my $who = $ssh->exec('who'); print($who); } else{ print "wrong password ! \n"; }

Error>>>>>> Pseudo-hashes are deprecated at /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Expect.pm line 60, <STDIN> line 3.,
Pseudo-hashes are deprecated at /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Expect.pm line 60, <STDIN> line 3.
Pseudo-hashes are deprecated at /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Expect.pm line 60, <STDIN> line 3.
Pseudo-hashes are deprecated at /usr/lib/perl5/site_perl/5.8.0/Net/SSH/Expect.pm line 60, <STDIN> line 3.
Starting SSH...
Testing login output...
SSHProcessError The ssh process was terminated. at ./ssh_example line 34

Replies are listed 'Best First'.
Re: using user input with net::ssh:expect
by alexm (Chaplain) on Aug 11, 2009 at 18:52 UTC

    I tried your code and got the same weird error. Then, I chomped $unme and it worked fine:

    chomp(my $unme = <>);

    Note that I prefer using chomp over chop, but using the latter won't make a difference in this case.