Skip to content

Instantly share code, notes, and snippets.

@rdebeasi
Last active October 1, 2015 21:47
Show Gist options
  • Save rdebeasi/f11c31938ffa40ec445d to your computer and use it in GitHub Desktop.
Save rdebeasi/f11c31938ffa40ec445d to your computer and use it in GitHub Desktop.
Bash Script to feed a remote log via ssh to a local file.
#!/bin/bash
#
# Usage:
#
# server logfile/path output/path
# example sshtail.sh [email protected] /var/log/apache2/error.log ~/tmp/error.local.log
[ "$1" == "--help" ] && { printf "Usage: server logfile/path output/path\n"; exit; }
# Delete the file so we don't output anything until after we connect
rm $3
# Watch log in the background, adding a new line after each log entry.
# http://unix.stackexchange.com/a/3135
tail -f $3 | sed G &
printf "\nConnecting...\n"
ssh $1 "tail -f $2" >>$3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment