Move "2>&1" to the end of the crontab entry
Printable View
Move "2>&1" to the end of the crontab entry
The command to run your script from cron should be
Code:/home/trevor/backuplogs/scripts/dailybackup >>/mylogs/diagnostic 2>&1
I'm an idiot.
The script didn't have execute permissions, and it called sudo.
Have now fixed these and I'm experimenting - will report back.
Just tested this, and (fingers crossed!) I think it is all working.
Fantastic!
Could I just trouble you with a couple of queries, because while I am familiar in general with programming, I am a bash newbie...
what is the syntax in
I understand that this is meant to re-execute as root, but I don't understand how it works.Code:if [ "$(id -u)" != "0" ]; then
sudo "$0"
exit $?
fi
What does the following? I don't get what the bracket symbols do but it seems to be some sort of existence check for the directory?
and I'm guessing the following is a kind of "then" statement to make the directory if it doesn't exist?Code:[ -d /media/Elrond ]
Many thanks for your help btindie, I honestly didn't think I'd find a way out of this :PCode:|| mkdir /media/Elrond
Trevor
That checks to see if root is running the script, and if not, runs it with sudo.
As for that one, the -d part checks to see if a directory exists or not.Quote:
What does the following? I don't get what the bracket symbols do but it seems to be some sort of existence check for the directory?
and I'm guessing the following is a kind of "then" statement to make the directory if it doesn't exist?Code:[ -d /media/Elrond ]
Many thanks for your help btindie, I honestly didn't think I'd find a way out of this :PCode:|| mkdir /media/Elrond
Trevor
It would look something like this:
Code:if [[ -d /path/to/some/dir ]]
then
do this
else
do that
fi
http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html
Here is a pretty in depth guide to BASH. The page linked is an explanation of the basic usage of "if", along with some of the primary expressions like the [ -d /file/path ] in your script. Very good info to keep bookmarked while learning the ways of BASH
Thanks to all of you for your help (and the bash tutorial link).
Not only do I have a working backup, but I actually understand how it works.
Many many thanks.
I'll switch the thread to SOLVED