Skip to content

Instantly share code, notes, and snippets.

@riywo

riywo/ssh_tailf.pl

Created Aug 7, 2012
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@riywo 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