Re: [Ssh-sftp-perl-users] How can I get a second chance after an authentification failure
Brought to you by:
dbrobins
From: Rafe S. <raf...@iq...> - 2006-01-09 10:56:00
|
Miky J wrote: >Hi, > >I'm not the only one to log on some machines and >sometimes passwords change here. > >When I do >$ssh->login($login, $password); >with $password='wrong password' >I'd like my script to make a second attempt with >$password='good password' > >I have tryed >if ($ssh->login($login, $password)) { ... } >else { retry to connect } > >but it didn't work. > >Does anyone know how to do that ? > > > > If I remember correctly, the ssh lib dies the script after a login attempt fails... so you need to wrap the login attempt in an eval and then try with a new password if it fails..... If you search the list archives I'm pretty certain its there.... In fact, if memory serves I asked that very question about 18 months ago :-> (I did a debug step through the code and found the die line) apologies for the piss poor code :-> I think you could just put in a second login attempt where I have the write_results sub below. Rafe use Net::SSH::Perl; eval { local $SIG{ALRM} = sub { write_results( $opt{C}, 2, "Timeout Failure", 1 ) }; alarm $TIMEOUT; $ssh = Net::SSH::Perl->new( $host, options => [ "Debug 1", "Protocol 2" ] ); } || write_results( $opt{C}, 2, "Connection Failure", 1 ); eval { $pwd = $ssh->login( $username, $password ) }; if ( !$@ ) { my $cmd = q( uname); my ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); # print "host: $stdout\n"; chomp($stdout); if ( $stdout eq "Linux" ) { $cmd = "ps -ef |grep -i \"$process\" |grep -v grep |grep -v process.pl"; } else { $cmd = "/usr/ucb/ps -auxww |grep -i \"$process\" |grep -v grep |grep -v process.pl"; } ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); |