Skip to content

Instantly share code, notes, and snippets.

@riywo
Created August 7, 2012 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riywo/3287212 to your computer and use it in GitHub Desktop.
Save riywo/3287212 to your computer and use it in GitHub Desktop.
perlでssh tail -fをいい感じに
use strict;
use warnings;
my $host = $ARGV[0] or die;
my $ssh = 'ssh -t';
my $cmd = 'tail -F -n0 /tmp/hoge.log';
my $pid = open my $fh, '-|', qq/$ssh $host '$cmd'/ or die;
while (<$fh>) {
if (/hoge/) {
print $_;
last;
}
}
kill TERM => $pid;
close $fh;
print "finished\n";
__END__
local$ perl ssh_tailf.pl host1
host1$ echo fuga >> /tmp/hoge.log
host1$ echo hoge >> /tmp/hoge.log
hoge
Killed by signal 15.
finished
local $
@riywo
Copy link
Author

riywo commented Aug 7, 2012

Killed by signal 15.を消したいのだが、pipeのopenでshでstderrを/dev/nullに捨てるとkill送ったらttyがおかしくなるので仕方なく。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment