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

lettinf an external basgh command timeout inside eval

Thread Next
October 21, 2009 03:08
lettinf an external basgh command timeout inside eval
Message ID:

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


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About