SolvedCron job not running properly

Member

I have a user called medusa with password *. I can successfully login to that user using su - medusa and executing a script in that user's home directory. The script creates a zip archive of some files and pushes it via rsync to another location.
As I'd like that script to be executed automatically once every hour I created a cron job for/with that user using crontab -e:

Code:

0 * * * * /home/medusa/scripts/myscript.sh > cron_log_myscript.txt

Then I logged out of the user and rebooted the machine.

I see in the cron log that the cron job is being executed. However, the script fails at the stage where it is supposed to create a ZIP archive. The script is terminated and returns my own error string:

As mentioned the script runs fine if I manually execute it. Therefore, I suspect that there are some permissions problems.
Does a user require any specific permissions to run a cron job?
How can I debug this?

Member

I tried what you suggested and the zip no longer fails. However, after the zipping operation I am using rsync to push that zip to a remote location. The zip never arrives there so the rsync operation doesn't appear to be working.
I am using rsync over SSH:

Member

It is actually working well now. The modification proposed in your first post regarding the PATH is what fixed it.
I didn't see it working because another script was now able to try to push 25GB of backup to my poor 10GB server. Hence the script I was trying to get working with your help now mailed me that the remote is out of disk space.

Is manually setting that PATH in the cron job declaration just a temporary work-around or is that how it is supposed to be done?

Active Member

After the recommendation I read on a similar post, one thing I do is to use an ABSOLUTE path for everything, for both commands and files passed as argument. That's a sure bet, and simple. No ./ anywhere.

Member

Thank you for the recommendation about using absolute paths for all binaries.
Is it a good idea to have variables for these paths at the top of the script so that someone who wants to modify/port the script only has to change the paths stored in those variables?

Something like:

Code:

BIN_RSYNC=/usr/local/bin/rsync

And then using BIN_RSYNC everywhere in the script where rsync is called.