Last active
October 1, 2015 21:47
-
-
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.
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 | |
# | |
# 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