Skip to content

Instantly share code, notes, and snippets.

@oz123
Created December 2, 2014 15:55
Show Gist options
  • Save oz123/c4fc272082f60ba4fe53 to your computer and use it in GitHub Desktop.
Save oz123/c4fc272082f60ba4fe53 to your computer and use it in GitHub Desktop.
I was ask to collect all logs from different host to a central place. I was also asked to implement this with rsync. So here is what I came up with:
cronjob:
========
* 1 * * * rsync -e 'ssh -v -i .ssh/log_coll_id_rsa logcol@server' -aP /var/log/mongodb/*.s server:.
### There results:
On the server called server you will see in the home directory of the ssh user you created a directory with the log files for each host
you installed the ssh key, the script and the cron job.
ls ~
host1 host2 host3
#!/bin/sh
DEST=$(echo $(grep $(echo $SSH_CONNECTION | cut -d " " -f 1) /etc/hosts) | tr -s " " | cut -d " " -f 2)
SOURCE=/var/log/mongodb/
rsync --server -logDtpre.iLsf $SOURCE ~/$DEST
# I installed this file to /usr/local/bin
command="/usr/local/bin/logsync",no-agent-forwarding,no-port-forwarding,no-user-rc,no-X11-forwarding,no-pty ssh-rsa AAA...YOUR PUBLIC KEY HERE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment