0

Hi I am attempting to use rsync to copy files between two linux servers. both on 10.04.4

I have set up the ssh and a script running under a cron job. this is the message i get back from the cron job.

To: mark@ubuntu Subject: Cron ~/rsync.sh Content-Type: text/plain; charset=ANSI_X3.4-1968 X-Cron-Env: X-Cron-Env: X-Cron-Env: X-Cron-Env: Message-Id: <20120708183802.E0D54FC2C0@ubuntu> Date: Sun, 8 Jul 2012 14:38:01 -0400 (EDT)

rsync: link_stat "/home/mark/#342#200#223rsh=ssh" failed: No such file or directory (2) rsync: opendir "/Library/WebServer/Documents/.cache" failed: Permission denied (13) rsync: recv_generator: mkdir "/Library/Library" failed: Permission denied (13) * Skipping any contents from this failed directory * rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1060) [sender=3.0.7]

Q.1 can anyone tell me why I get this message -->

rsync: link_stat "/home/mark/#342#200#223rsh=ssh" failed: No such file or directory (2)

the script is:

    #!/bin/bash
SOURCEPATH='/Library'
DESTPATH='/Library'
DESTHOST='192.168.1.15'
DESTUSER='mark'
LOGFILE='rsync.log'
echo $'\n\n' >> $LOGFILE
rsync -av –rsh=ssh $SOURCEPATH $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE
echo “Completed at: `/bin/date`” >> $LOGFILE

Q2. I know I have several problems with the permissions all of the files I am copying usually require me to use sudo to manipulate them. My question is then is there a way i can run this job without giving my user root access or using root in the login ??

Thanks for the help .

2 Answers 2

0

As for Q1 I'm guessing that you have put the double dash before "rsh" in as an "en-dash", i.e. a single character: — so rsync is interpreting it as a filename rather than an option to the program.

For Q2 if you want to give a non-root user permission to do things with files it wouldn't otherwise be able to manipulate you're either going to have to change the permissions of the files or elevate the permissions of the user, e.g. through use of sudo.

sudo can be configured to allow certain users to execute certain commands as root with no password prompt, so the thing you need to do is separate out the things you need to do as root into a script which does them (and only them), and then allow that script to be called as root. Here is an example from one of my /etc/sudoers files:

Cmnd_Alias      F2B_CLIENT_PING = /usr/bin/fail2ban-client ping
nagios          ALL             = NOPASSWD: F2B_CLIENT_PING

What the above does is allows the "nagios" user to execute "/usr/bin/fail2ban-client ping" as root using sudo, without being prompted for a password. I use it in my monitoring.

You'd have something like:

Cmnd_Alias RSYNC_BACKUP = /usr/local/sbin/backup_my_stuff_with_rsync.sh
youruser   ALL          = NOPASSWD: RSYNC_BACKUP

and then in your cron you'd call sudo /usr/local/sbin/backup_my_stuff_with_rsync.sh

You can test it on the command line first to verify that it doesn't ask for password.

Note that running a script as root is a big deal and so you must ensure that your script is secure and correct. If you can find any way to do this as non-root, that would be better.

3
  • yes I had messed up on the - sign thanks. Q2. However I believe I can't run sudo in the cron job as it will reqiure a password
    – MB.
    Jul 8, 2012 at 21:18
  • I've edited the answer to include an example of how to configure sudo to not ask for a password. Thanks for accepting the answer.
    – grifferz
    Jul 9, 2012 at 10:04
  • thanks i'll give it a try.I tried to upvote your answer but I'm too new here...
    – MB.
    Jul 10, 2012 at 11:47
0

Fix up the rights of These Files, using

chown -R Mark:Mark *

you will have to do that for all These .dot dirs unless you get Fanny with find -exec

1
  • my problem with doing that is I'm going to get permission problems for sure as the files further down the hierarchy are owned by the apache server and webdav publishing user etc...
    – MB.
    Jul 8, 2012 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .