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
  • Have you tried temporarily doing chmod 777 /bin/ScriptThatCopiesBackup.sh and rebooting to see if it works? – Patrick Cook Feb 5 '16 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 '16 at 4:24
4

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).

  • 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. – G-Man Feb 5 '16 at 4:52
  • You're not wrong about the confluence of two problems. – DopeGhoti Feb 5 '16 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. – MikeMcHenry32 Feb 8 '16 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 '16 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. – MikeMcHenry32 Feb 8 '16 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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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