in reply to Re: perl -e in ssh
in thread perl -e in ssh
sub shell_quote { my $s = @_ ? $_[0] : $_; return $s if $s =~ /^[a-zA-Z0-9-_]+\z/; $s =~ s/'/'\\''/g; return "'$s'"; } my $server = 'localhost'; my $cmd = 'ls -ltra'; my $timeout = 3; my $watchdog = <<'__EOI__'; $t = shift; $SIG{ALRM} = sub { kill INT => $p }; exec(@ARGV) unless $p = fork; alarm $t; waitpid $p, 0 #exit(...) __EOI__ my $watchdog_cmd = join ' ', map shell_quote, perl => "-e$watchdog", $timeout, $cmd; my $ssh_cmd = join ' ', map shell_quote, ssh => $server, $watchdog_cmd; my $output = `$ssh_cmd`;
But wouldn't it make more sense to include ssh in the timeout?
... my $ssh_cmd = join ' ', map shell_quote, ssh => $server, $cmd; my $watchdog_cmd = join ' ', map shell_quote, perl => "-e$watchdog", $timeout, $ssh_cmd; my $output = `$watchdog_cmd`;
Tested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: perl -e in ssh
by Anonymous Monk on Apr 13, 2010 at 18:42 UTC | |
|
Re^3: perl -e in ssh
by Anonymous Monk on Apr 13, 2010 at 19:05 UTC | |
|
Re^3: perl -e in ssh
by Anonymous Monk on Apr 13, 2010 at 19:06 UTC | |
by ikegami (Patriarch) on Apr 13, 2010 at 19:22 UTC |