SOLVED Bash script errors when run from cron, works fine from shell

bobpaul

Dabbler
Joined
Dec 20, 2012
Messages
23
I have a bash script used for workstation backups that runs via cron (one entry per workstation). The script does some tasks (wake on lan to wake the machine, etc) as well as managing and filtering logs from the rsync process. After updating to FreeNAS

But for testing, I've whittled the script down to simply:

Code:
#!/usr/local/bin/bash

/usr/local/bin/rsync -a --password-file=/mnt/tank/sekrets/rsync.secret --force --ignore-errors machine-name::etc /mnt/tank/backup/machine-name/current/etc -v --numeric-ids --dry-run


When I run the script from the shell it works fine.

When the script runs via cron, via "Run Now" from the web interface, or via /usr/local/bin/midclt call cronjob.run 8, rsync fails with

Code:
@ERROR: auth failed on module etc
rsync error: error starting client-server protocol (code 5) at main.c(1671) [Receiver=3.1.3]


I'm currently banging my head against the wall; I can't figure out what's different between the two cases.

Probably I should re-work this to tunnel everything over ssh (it's rather absurd that I'm not doing that already), but does anyone have any idea why it's failing in the cron environment or have suggestions on how to troubleshoot this?
 
Last edited:

bobpaul

Dabbler
Joined
Dec 20, 2012
Messages
23
2 environment variables of note are missing when run from /usr/local/bin/midclt call cronjob.run 8 (which is what cron calls)

Code:
HOME=/root
USER=root


rsync implicitly prepends ${USER}@ to the connection URI if you don't explicitly provide one.

I find the middleware's behavior a bit surprising since one of the settings when adding a crontask via the WebUI is selecting a user to run as... I feel like setting the environment ($USER, $HOME, etc) to act as that user should be part of that. But it's an easy fix and I feel kinda dumb I didn't spot it sooner >_<
 
Top