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

Hi, i am running perl scripts to several hundred servers through foreach loop, i have tried to figure out how i can skip servers that gives Permission Denied message so that my scripts run to the end. Any tips would be lovely. Thanks, jho.

Replies are listed 'Best First'.
Re: net ssh loop
by salva (Canon) on Jul 21, 2010 at 10:46 UTC

      Hi, exactly same error happens with simpler code.

      <code> my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($LS_OUT, $LS_ERR, $LS_EXIT) = $ssh->cmd('ls -la'); print "This is END where i want to see\n"; <code> _jho

        First, to include code in your posts use <code>your code here</code>, there is a backslash in the closing tag!

        Regarding your original question, wrap the code that can fail inside eval:

        eval { my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($LS_OUT, $LS_ERR, $LS_EXIT) = $ssh->cmd('ls -la'); }; $@ and print "SSH failed: $@"; print "This is END where i want to see\n"

        i have tried already. <code> my $ssh = Net::SSH::Perl->new($host); if ($ssh->login($user, $pass)){ my ($LS_OUT, $LS_ERR, $LS_EXIT) = $ssh->cmd('ls -la'); }else{ print "The END\n";} <code>