Skip to content

Instantly share code, notes, and snippets.

@sh2
Created August 8, 2012 01:55
Show Gist options
  • Save sh2/3291358 to your computer and use it in GitHub Desktop.
Save sh2/3291358 to your computer and use it in GitHub Desktop.
Execute tail -f and watch a specific line on a remote host.
#!/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