Created
August 7, 2012 16:46
-
-
Save riywo/3287212 to your computer and use it in GitHub Desktop.
perlでssh tail -fをいい感じに
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Killed by signal 15.
を消したいのだが、pipeのopenでshでstderrを/dev/null
に捨てるとkill送ったらttyがおかしくなるので仕方なく。