Synchronize remote hosts
A simple script to sync remote hosts, steps to achieve it :
1.Avoid SCP prompting for password [ local host ] => ssh-keygen -t dsa -b 2048 -f ~/key.pub
2.SCP the key for the first time to the [ remote host ] =>
scp ~/key.pub remoteuser@remotehost:/home/remoteuser/
- In remote host : [ Authorize the Host from which key was received ]
if [ ! -d .ssh ]; then mkdir .ssh chmod 700 .ssh fi mv key.pub .ssh/ cd .ssh/ if [ ! -f authorized_keys ]; then touch authorized_keys chmod 600 authorized_keys ; fi cat key.pub >> authorized_keys
"rsync + Cron jobs" to keep both the hosts in sync :
#
!/bin/sh
RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/home/whoami
/key.pub
LOCAL_PATH=/sync/dir
REMOTE_USER=remote-user
REMOTE_HOST=remote-host
REMOTE_PATH=/remote/dir
$RSYNC -az -e "$SSH -i $KEY" \ $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH
#
Setting up cron
mv syncScp.sh /etc/cron.daily/
or
crontab -e
0 5 * * 5 /home/you/syncScp.sh
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs