Results 1 to 6 of 6

Thread: Confused by quotes in shell script

  1. #1
    Join Date
    Sep 2005
    Location
    The land downunder
    Beans
    29

    Confused by quotes in shell script

    Hi all,

    I am trying to setup an automated rsync job between my server and client. The server ssh daemon listens to port 8888 (for security reasons) and as such I have to issue the following command to get rsync to work

    Code:
    rsync -avz --rsh='ssh -p 8888' user@server:/remote/dir /local/dir/
    Hard coding this into a sh script works, however I would like to tidy things up and use variables. So I split everything up and have the following:

    Code:
    RSYNC=/usr/bin/rsync
    RSYNC_OPTIONS="-avz  --rsh='/usr/bin/ssh -p 8888'"
    RSYNC_REMOTE_HOST="user@server"
    
    $RSYNC $RSYNC_OPTIONS $RSYNC_REMOTE_HOST:/remote/dir /local/dir/
    But this results in rsync failing with the following messages:

    Code:
    building file list ... rsync: link_stat "/usr/local/bin/8888'" failed: No such file or directory (2)
    rsync: link_stat "/usr/local/bin/user@servr:/remote/dir" failed: No such file or directory (2)
    I'm guessing the single quotes are interfering in some way. Any ideas?

    ws
    --
    breathe
    --

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Confused by quotes in shell script

    edit: nonsense, see later post

    you need to quote the variables when using them too:
    $RSYNC "$RSYNC_OPTIONS" $RSYNC_REMOTE_HOST:/remote/dir /local/dir/

    the quotes in the assignment are not saved in the variable
    Last edited by MadCow108; December 28th, 2010 at 03:26 PM.

  3. #3
    Join Date
    Sep 2005
    Location
    The land downunder
    Beans
    29

    Re: Confused by quotes in shell script

    MadCow,

    Thanks for the info, however rsync now complains about:

    Code:
    rsync: -avz --rsh='ssh -p 8888': unknown option
    rsync error: syntax or usage error (code 1) at main.c(1318) [client=2.6.9]
    Any ideas?

    ws
    --
    breathe
    --

  4. #4
    Join Date
    Feb 2010
    Location
    Silicon Valley
    Beans
    1,898
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Confused by quotes in shell script

    One idea: you can eliminate the "-p 8888" by putting that info in your $HOME/.ssh/config file. That will at least get rid of some spacing issues.

    Code:
    $ cat $HOME/.ssh/config
    Host server.name.here
        Port 8888

  5. #5
    Join Date
    Sep 2005
    Location
    The land downunder
    Beans
    29

    Re: Confused by quotes in shell script

    Hi gmargo,

    You beat me to it. I have just changed my ssh_config file to remove the need for -P 8888.

    Thanks for everyones help none the less.

    Cheers ws
    --
    breathe
    --

  6. #6
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Confused by quotes in shell script

    ups sorry I did not read your post properly, quoting is nonsense.

    you have to force bash to reevaluate the expanded options with eval to get the quoting right:
    eval "$RSYNC $RSYNC_OPTIONS $RSYNC_REMOTE_HOST:/remote/dir /local/dir/"
    Last edited by MadCow108; December 28th, 2010 at 03:16 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •