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 $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Killed by signal 15.
を消したいのだが、pipeのopenでshでstderrを/dev/null
に捨てるとkill送ったらttyがおかしくなるので仕方なく。