Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a .sh script that creates a .tar.gz file and transfer's it to a remote server using RSA keys for authentication.

The script will run from terminal but it will not when I try to set it up as a Cron job.

I receive an email from the Cron Daemon stating this failure : "/bin/sh: /home/ Permission denied" , and the file is not transferred to the other server.

I have established the most likely cause from this askubuntu post that this is most likely due to the fact that "Cron" passes a minimal set of environment variables to your jobs.

The fix seems to be to include the


# rest of script follows

Any help with how to configure this would be greatly apprecited.

I am running Ubuntu Server 11.04

EDIT : ls -la gives -rw-r--r-- 1 root root 1053 2012-10-13 15:08

share|improve this question
Based on what you've told us (ie, the contents of cron's email) other explanations present themselves. Could you edit the output of ls -la /home/ into your question? – MadHatter Oct 15 '12 at 11:14
Added in there @MadHatter – Ríomhaire Oct 15 '12 at 11:21
up vote 0 down vote accepted

Thanks for the ls output. It seems that cron's complaint about the file not having the right permissions can be taken at face value (specifically, it lacks execute permissions); try doing chmod 755 ./home/ and see if that helps.

Edit: I'm glad we got that sorted out. You should firstly look at which user is running this job, under cron, and examine the ownership of the backupdir directory. The user needs to have permissions to write in that directory; blindly chmodding things won't help.

share|improve this answer
Thanks @MadHatter, that has helped. I now get emailed the output of the cron. However, the script saves the server-backup.tar.gz in a directory named backupdir. And the cron is unable to access that folder to change scp it across. Should I run the same chmod 755 on backupdir, to fix this? Thanks very much – Ríomhaire Oct 15 '12 at 11:51

The "Permission denied" message seems to be suggesting that the user that cron is running the script as doesn't have suitable permission to access the script /home/

Check that the user who's crontab is being used has at least r-x on /home and on

share|improve this answer

You can set any environment variable you like in a crontab. One way is to put a line in the crontab file in the format


That environment variable will then be set for any cron jobs which appear after that line in the file. If you want to be sure that it only applies to that command, just put the variable declaration at the start of the command, in the same way you would if changing a variable for just one command at the console:

varname=value command

So it might look like

0 5 * * * varname=value command

For a personal crontab or

0 5 * * * root varname=value command

For a system one.

Note: I've answered your question, but the others are right that this is probably not the cause of your problem.

share|improve this answer

It would probably be best to append to $PATH than to overwrite it in this instance.


You could also debug what your PATH variable is set to by using the following

#!/usr/bin/env bash
logger "Path-dump: "${PATH}

You can check the output in /var/log/syslog and you should see some output

cat /var/log/syslog | grep "Path-dump"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.