Created
August 8, 2012 01:55
-
-
Save sh2/3291358 to your computer and use it in GitHub Desktop.
Execute tail -f and watch a specific line on a remote host.
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
#!/bin/bash | |
TARGET_HOST=localhost | |
TARGET_FILE=/tmp/test.log | |
TARGET_LINE='^CRIT' | |
ssh $TARGET_HOST perl <<_EOF_ | |
use strict; | |
use warnings; | |
use File::Tail; | |
\$| = 1; | |
my \$file = File::Tail->new( | |
name => '$TARGET_FILE', | |
maxinterval => 1 | |
); | |
while (my \$line = \$file->read()) { | |
print \$line; | |
if (\$line =~ /$TARGET_LINE/) { | |
last; | |
} | |
} | |
_EOF_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment