First try some simple cronjobs and build from here:
0 12 * * * user echo 'Hello, World!' >> /tmp/test.log 2>&1
1 12 * * * user ssh anotheruser@anotherhost ls >> /tmp/test.log 2>&1
2 12 * * * user rsync -e ssh anotheruser@anotherhost:/path/to/small/dir /tmp/test-dir >> /tmp/test.log 2>&1
Avoid using too many options at first, but using 2>&1
is important for getting any error messages. You could also use 2>/tmp/test-error.log
to send them to a separate file. Normally, cron generates an email if, and only if, there is any output. This mail is sent to the email address mentioned in the MAILTO environment variable set in crontab or to the local unix user the job is run as if MAILTO is not set. If you don't have a mail server installed or are unsure how to access it, then you can just redirect all output to a file instead. Another thing to look at is setting SHELL. By default, cron uses /bin/sh which is normally just fine, and may even be a symlink to /bin/bash on some systems, but if not and you expect to use bash-isms in your command, you can add SHELL=/bin/bash
or whatever is appropriate before your job listings.
Another issue I can see with your above crontabs is spaces. Since the commands work at a normal shell, it's probably not the issue, but do be wary of using spaces when using certain remote ssh commands like: ssh server ls "Music Videos"
, spaces in such commands need to be double escaped due to the fact that both the local shell and remote shell may interpret them. The correct command should be something like this: ssh server ls "Music\\ Videos"
or ssh server ls '"Music Videos"'
The last thing I can think of is that ssh is failing authentication. I assume you are using public key authentication. Where is your public key being stored? Is it in ~/.ssh/id_rsa
as an unencrypted private key, or do you have it loaded in a SSH Public Key Agent? If it's loaded in an agent because the on-disk copy is encrypted, you will need to make sure SSH_AUTH_SOCK is manually set in crontab to point to an agent that will be running when rsync does. I normally keep my private keys encrypted on-disk and keep ssh-agent running in the background with a fixed socket path. For example, I run ssh-agent -a /tmp/user.agent
followed by SSH_AUTH_SOCK=/tmp/user.agent ssh-add .ssh/id_rsa
to load in the private key to the agent. I have these two commands in a script that I run manually after each reboot since I need to enter in a passphrase to unlock the private key. Then I have SSH_AUTH_SOCK=/tmp/user.agent
in my crontab file for my automatic cronjobs to use.
~
with the path?