develooper Front page | perl.beginners | Postings from October 2009

lettinf an external basgh command timeout inside eval

Thread Next
From:
cerr
Date:
October 21, 2009 03:08
Subject:
lettinf an external basgh command timeout inside eval
Message ID:
9bf49ec8-443f-4859-8c3e-6929c98abecf@g1g2000pra.googlegroups.com
Hi,

I wanna execute an external bash command but timeout if it's taking
longer than XX seconds. I've tried it like this:
eval {
	local $SIG{ALRM} = sub {die "alarm\n"};
	alarm $timeout;
	$test = `$sshpassPATH . " -p ".$clientpw." ssh root@".$ip." ".
$RemcksumPATH." ".$RemcksumPATH." > ".$ckCKSUMclt`;
	alarm 0;
      };

      if ($@) {
	die unless $@ eq "alarm\n";
	print "DEBUG: timed out\n";
      }
      else {
	print "DEBUG: didn't time out\n";
      }

      print "DEBUG: script continues...\n";

But in this case the script tells me
sshpass: Failed to run command: Permission denied
$sshpassPATH contains "./ssdpass" which is present and executable by
the current user and if i put that whole string in between `` into a
system() command, it executes just fine. What am i doing wrong? Also
do I need to be using the ``? What's happening with $test? Is this
required?

Thanks,
Ron


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About