LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2010, 09:07 PM   #1
someshpr
Member
 
Registered: Jul 2009
Location: WI, USA
Distribution: Debian 8, Ubuntu 16.04, CentOS 7
Posts: 143

Rep: Reputation: 28
shell script wrapper for automating rsync


Hi,
I wanted to write a shell script wrapper for automatically syncing some folders across machines. The machines are spread over two sub-domains in the parent domain (grp.vpncc.org and hpc.vpncc.org). I have set up public and private keys over the machines so that I can rsync without password. I have three machines archean, jurassic and silurian under grp.vpncc.org which uses a central nfs mounted home directory (/nfs/cretaceous/home/). From these three machines I usually would like to run this syncing. The fourth machine of my interest is cluster.hpc.vpncc.org, but this is I have checked individual rsync commands and that works fine. But when I try to use rsync via the script (autosync.sh):
Code:
#!/bin/bash

arg=$1
usr="somesh@$2"
src=$3
dest=$4

host=`hostname`

case $host in
        archean.grp.vpncc.org)
                key="\"ssh -i /home/somesh/.keys/archean_rsa\""
                ;;
        silurian.grp.vpncc.org)
                key="\"ssh -i /home/somesh/.keys/silurian_rsa\""
                ;;
	jurassic.grp.vpncc.org)
		key="\"ssh -i /home/somesh/.keys/jurassic_rsa\""
		;;
	*)
          	echo "Non Destination:" $host
		;;
esac

echo $arg
echo $key
echo $usr
echo $src
echo $dest

f="rsync $arg -e $key $usr:$src $dest"
echo $f
rsync $arg -e $key $usr:$src $dest
I get this error:
Code:
somesh@archean temporst$ ./autosync.sh -avz cluster.hpc.vpncc.org /gpfs/home/somesh/myScripts/ .
-avz
"ssh -i /home/somesh/.keys/archean_rsa"
somesh@cluster.hpc.vpncc.org
/gpfs/home/somesh/myScripts/
.
rsync -avz -e "ssh -i /home/somesh/.keys/archean_rsa" somesh@cluster.hpc.vpncc.org:/gpfs/home/somesh/myScripts/ .
building file list ... rsync: link_stat "/home/somesh/.keys/archean_rsa"" failed: No such file or directory (2)
rsync: link_stat "/nfs/cretaceous/home/somesh/myScripts/temporst/somesh@cluster.hpc.vpncc.org:/gpfs/home/somesh/myScripts/." failed: No such file or directory (2)
done

sent 29 bytes  received 20 bytes  98.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at main.c(892) [sender=2.6.8]
But when I use the command
Code:
rsync -avz -e "ssh -i /home/somesh/.keys/archean_rsa" somesh@cluster.hpc.vpncc.org:/gpfs/home/somesh/myScripts/ .
it works fine.

What am I doing wrong?

All the systems run RHEL 5 or CentOS 5.

TIA,
 
Old 06-02-2010, 03:54 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
The "" in the link_stat error seems to suggest it's a quoting issue - it seems to look for a file called
/home/somesh/.keys/archean_rsa"

Since the key value does not need any expansion, using single quotes could help.
Something like:
Code:
key='ssh -i /home/somesh/.keys/archean_rsa'
...
rsync $arg -e "$key" $usr:$src $dest
The script should also exit when an inappropriate host is specified (* case), as it would
still continue with an empty $key as it is now.
 
1 members found this post helpful.
Old 06-02-2010, 08:10 AM   #3
someshpr
Member
 
Registered: Jul 2009
Location: WI, USA
Distribution: Debian 8, Ubuntu 16.04, CentOS 7
Posts: 143

Original Poster
Rep: Reputation: 28
Thanks timmeke! That works!

Yes, I should add an exit statement for * case.

BTW, what are the differences of "" and ''?
 
Old 06-03-2010, 01:31 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Plz read the section on quoting in
Code:
man bash
In practice, single quotes are for literal strings - no expansion of e.g. variables is done.
So '$key' would match the exact string $key, without substituting the value of the variable.

Double quotes do expand.
 
  


Reply

Tags
rsync, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating sftp using a shell script bhandu Linux - Newbie 3 07-17-2007 01:56 AM
automating lynx in a shell script yimboli Programming 15 04-04-2007 02:15 AM
Automating FTP upload via a shell script? Spitty Programming 5 01-16-2006 10:28 PM
Trouble when automating ftp with shell script hari_s_82 Linux - Newbie 2 09-23-2004 02:17 AM
Automating a playlist using shell script... DesiLILO Linux - Newbie 4 04-02-2004 11:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration