On Oct 21, 8:31 am, jimsgib...@gmail.com (Jim Gibson) wrote: > At 3:59 PM -0700 10/20/09, cerr wrote: > > >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`; > > Backquotes `` create a double-quote context. You cannot use > double-quotes or the concatenate operator . within that context. Put > your command-line in a variable:
Exactly that works, great thanks. Although I still got another issue. My =code looks like this now: eval { local $SIG{ALRM} = sub {die "alarm\n"}; alarm $timeout; $cmd = $sshpassPATH." -p ".$clientpw." scp ".$SrcFileLoc." root@". $ip.":/usr/share/tmp/"; print "cmd: <".$cmd.">\n"; `$cmd`; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; print "DEBUG: scp timed out, try to continue update\n"; syslog('info', "scp timed out, try to continue update"); } else { print "DEBUG: succesfully scp-ed $SrcFileLoc to $ip:/usr/share/tmp/! \n"; } $timeot is set to 10. Now when I pull the plug while to copying action is taking place, it actually just hangs and does not timeout. It however works in other situations. I don't understand... Any hints or suggestions? I know using sshpass is conssidered unsecure but there's no way around it in this situation, we've spent quite some time researching various public key alternatives. Thanks for suggestions and hints! Ron -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/