Skip to content

Instantly share code, notes, and snippets.

@luke10x
Created April 16, 2014 21:58
Show Gist options
  • Save luke10x/10937274 to your computer and use it in GitHub Desktop.
Save luke10x/10937274 to your computer and use it in GitHub Desktop.
Syncs new lines in a remote log file to a local file then outputs it through tailable
#!/bin/bash
# Syncs new lines in a remote log file to a local file.
# Downloads remote file, and prints all lines that are
# not yet printed
source=$1
# Find the name for the locally copied file
hash=`echo "$source" | md5sum | cut -d " " -f 1`
mkdir -p ~/.tailable/temp/local-mirror
local_copy="$(readlink -f ~/.tailable/temp)/$hash"
# Copy remote file
timeout 3 scp "$source" "$local_copy" 1>/dev/null
error_code=$?
if [ "$error_code" -ne "0" ]; then
echo "`date` Failed to download file from '$source'" 1>&2
exit $error_code
fi
./tailable -f "$local_copy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment