in reply to Dealing with errors in subroutines
Originally I tried to check the return code (the $ret) or the return code of the run_ssh() that actually spawns the ssh process, but since the ssh spawned successfully (it just died soon after) it never returned any useful value, and the above command would break if the ssh object was already gone, or if the server was asking for a password (meaning my SSH keys were not set up on that host)my $rc = eval{( $ret =~ />\s*|$\s*\z/) or die "where's the remote prom +pt?";}; if($rc) { if($ret =~ m/[Pp]assword:/) { print("Couldn't connect to host\n"); } }
|
|---|