1

I use a PuTTY session to copy my nightly backups to another location. I log in as the root user and change directories to /store/BackupLocation which holds backups from the last 100 days. I can then run:

bash /bin/ScriptThatCopiesBackup.sh

This script copies my backups from /store/BackupLocation to another directory /store/BackupArchive

This all works perfectly, but I can't seem to schedule this script to run automatically in crontab. Instead I get the following permission error everyday:

/bin/bash: /bin/ScriptThatCopiesBackup.sh :Permission denied

My question is, why am I recieving this error message even though everything is done by root? And what can I do to resolve this?

Here are the permissions for my script:

-rw-r--r-- 1 root root 213 June 19 2013 ScriptThatCopiesBackup.sh

Here are my crontab settings:

30 16 * * * /bin/ScriptThatCopiesBackup.sh
2
  • Have you tried temporarily doing chmod 777 /bin/ScriptThatCopiesBackup.sh and rebooting to see if it works? Feb 5, 2016 at 4:20
  • 1
    777 is probably a bad idea; I'd suggest u+x to add the executable bit only to the file's owner.
    – DopeGhoti
    Feb 5, 2016 at 4:24

2 Answers 2

5

The problem is that your script is not set to be executable. chmod u+x /bin/ScriptThatCopiesBackup.sh will make the script runnable by its owner (in this case, root).

6
  • 1
    Well, the problem is that, when the OP runs the script manually, he says bash scriptname, but the command in the crontab entry is just scriptname … … … … … AND that the script is not set to be executable. Feb 5, 2016 at 4:52
  • You're not wrong about the confluence of two problems.
    – DopeGhoti
    Feb 5, 2016 at 17:40
  • I added what you suggested to crontab, but it still didn't work. However I am no longer getting ther permission error emails. Feb 8, 2016 at 14:28
  • It was not a suggestion of something to add to the cron table, but rather a suggestion of a command to run in situ to resolve the problem. The fact that you're no longer getting error emails indicates that the script is now working.
    – DopeGhoti
    Feb 8, 2016 at 17:42
  • First, thank you for taking the time to help me. But I really don't think the script is working. Because when I check my Archive directory the latest backups are missing. Feb 8, 2016 at 21:18
1

Your problem could be that you are editing the wrong crontab file. (Even though you said you are doing everything from root). Try editing the crontab file with crontab -u root.

It is also possible that your script is not executable. chmod +x /path/to/yourscript.shshould make it executable.

1
  • root should never not have access to anything that's not experiencing hardware failures.
    – DopeGhoti
    Feb 5, 2016 at 4:24

You must log in to answer this question.

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