Created
December 2, 2014 15:55
-
-
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:
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
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 |
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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment