LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-14-2010, 04:10 AM   #1
dbsput
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Rep: Reputation: 0
Using rsync with cron on different port.


Hi guys,

I'm trying to set-up a cron job that uses rsync to transfer back files from a remote server. ssh on the remote server is running on port 12345 but this seems to be a problem.

My script looks like this:

Code:
#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/home/username/.ssh/id_rsa.pub
RUSER=ruser
RHOST=hostip
RPATH=/var/usr_backups
RPORT=12345
LPATH=/var/backup/dhops

 $RSYNC --rsh='ssh -p$RPORT' -az -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH
This script runs an error suggesting that --rsh is incorrect.

How should I be specifying the port number?
 
Old 11-14-2010, 05:08 AM   #2
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
Hi,

environment variables in single quotes do not get resolved. I think this is the problem with the RPORT parameter. Use double quotes:

Code:
$RSYNC --rsh="ssh -p$RPORT"...
 
Old 11-14-2010, 05:34 AM   #3
dbsput
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks for the reply.

You were right and I tried your suggestion but I'm getting an error: --rsh=ssh -p32200: not found. It seems that the quotes are being stripped from the command.
 
Old 11-14-2010, 05:43 AM   #4
dbsput
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Isn't there a way you can specify hostA uses port X in a file somewhere? I remember seeing that a long time ago but I can't find it now. That would save me from needing to add it into the command.
 
Old 11-14-2010, 06:06 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,864

Rep: Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358Reputation: 6358
Yes, either in the users .ssh/config or system wide /etc/ssh/ssh_config files.
 
Old 11-14-2010, 06:14 AM   #6
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
You could escape the quotes with \:

Code:
$RSYNC --rsh=\"ssh -p$RPORT\"
The quotes are not interpreted by the shell. Could even be single quotes.

Last edited by cepheus11; 11-14-2010 at 06:16 AM.
 
Old 11-15-2010, 12:54 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Quote:
Originally Posted by dbsput View Post
Hi guys,

I'm trying to set-up a cron job that uses rsync to transfer back files from a remote server. ssh on the remote server is running on port 12345 but this seems to be a problem.

My script looks like this:

Code:
#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/home/username/.ssh/id_rsa.pub
RUSER=ruser
RHOST=hostip
RPATH=/var/usr_backups
RPORT=12345
LPATH=/var/backup/dhops

 $RSYNC --rsh='ssh -p$RPORT' -az -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH
This script runs an error suggesting that --rsh is incorrect.

How should I be specifying the port number?
rsync --rsh=ssh -az -e "ssh -i keyname -p12345" user@host:/path/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cron: rsync /var...--delete? erics_acvw Linux - Software 3 02-14-2010 05:25 PM
Cron and Rsync SimonTHK Linux - Software 16 10-07-2009 03:09 AM
rsync and cron numtre Linux - Software 1 01-08-2009 06:54 AM
Auto RSYNC Over SSH via Cron? carlosinfl Linux - General 1 09-10-2007 02:12 PM
Cannot execute rsync as a cron job jdaniels73 Linux - Software 2 09-03-2006 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:39 AM.

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