Re: Crontab doesn't complete a script
Hi Thomas The absolute path was the answer. Your explanation has added to my limited knowledge :-) Thanks Clive On 19/09/16 23:04, Thomas Schmitt wrote: Hi, Clive Menzies wrote: rsync_opts="-av --exclude-from=exclude_list --delete --delete-excluded" exclude_list=/root/uhuru_backup/exclude_list rsync: failed to open exclude file exclude_list: No such file or directory (2) The decisive difference between dialog and cron could be the current working directory. Try with an absolute path as parameter to --exclude-from= : rsync_opts="-av --exclude-from=/root/uhuru_backup/exclude_list --delete --delete-excluded" Or if you want to use the variable exclude_list, set it first. Then evaluate it by $exclude_list in the definition of variable rsync_opts: exclude_list=/root/uhuru_backup/exclude_list rsync_opts="-av --exclude-from=$exclude_list --delete --delete-excluded" This should yield the same rsync_opts content as above line. echo "Currently at line 17">>$log_file /root/uhuru_backup/uhuru.daily.sh: line 17: $log_file: ambiguous redirect Hm. To what value did you set the variable log_file ? If i set it to "/tmp/log_file", then the echo works in dash and bash. (We have to expect that cron uses the shell dash, whereas the dialog shell is probably bash.) If i set it to empty text, then dash complains dash: 2: Syntax error: newline unexpected bash says -bash: syntax error near unexpected token `newline' A blank would do it in bash but not in dash: $ log_file="/tmp/log file" $ echo "Currently at line 17">>$log_file -bash: $log_file: ambiguous redirect dash is brutal enough to really create a file "/tmp/log file". Have a nice day :) Thomas -- Clive Menzies http://freecriticalthinking.org
Re: Crontab doesn't complete a script
Hi, Clive Menzies wrote: > rsync_opts="-av --exclude-from=exclude_list --delete --delete-excluded" > exclude_list=/root/uhuru_backup/exclude_list > rsync: failed to open exclude file exclude_list: No such file or directory (2) The decisive difference between dialog and cron could be the current working directory. Try with an absolute path as parameter to --exclude-from= : rsync_opts="-av --exclude-from=/root/uhuru_backup/exclude_list --delete --delete-excluded" Or if you want to use the variable exclude_list, set it first. Then evaluate it by $exclude_list in the definition of variable rsync_opts: exclude_list=/root/uhuru_backup/exclude_list rsync_opts="-av --exclude-from=$exclude_list --delete --delete-excluded" This should yield the same rsync_opts content as above line. > echo "Currently at line 17">>$log_file > /root/uhuru_backup/uhuru.daily.sh: line 17: $log_file: ambiguous redirect Hm. To what value did you set the variable log_file ? If i set it to "/tmp/log_file", then the echo works in dash and bash. (We have to expect that cron uses the shell dash, whereas the dialog shell is probably bash.) If i set it to empty text, then dash complains dash: 2: Syntax error: newline unexpected bash says -bash: syntax error near unexpected token `newline' A blank would do it in bash but not in dash: $ log_file="/tmp/log file" $ echo "Currently at line 17">>$log_file -bash: $log_file: ambiguous redirect dash is brutal enough to really create a file "/tmp/log file". Have a nice day :) Thomas
Re: Crontab doesn't complete a script - SOLVED
On 19/09/16 22:10, Clive Menzies wrote: It didn't find the exclude_list I created. I modified the script to point to it but clearly the syntax is not right # Good rsync options for uhuru_backups. rsync_opts="-av --exclude-from=exclude_list --delete --delete-excluded" # exclude list location: exclude_list=/root/uhuru_backup/exclude_list echo "Currently at line 17">>$log_file The log reported thus: /root/uhuru_backup/uhuru.daily.sh: line 17: $log_file: ambiguous redirect rsync: failed to open exclude file exclude_list: No such file or directory (2) rsync error: error in file IO (code 11) at exclude.c(1179) [client=3.1.1] D'oh! I searched around a bit and realised I'd over-complicated it. This works :-) # Good rsync options for uhuru_backups. rsync_opts="-av --exclude-from=/root/uhuru_backup/exclude_list \ --delete --delete-excluded" Thanks Thomas, I'd still be going round in circles. Regards Clive -- Clive Menzies http://freecriticalthinking.org
Re: Crontab doesn't complete a script
On 19/09/16 12:31, Thomas Schmitt wrote: The classic remedy would be to set the missing variables inside the cronjob script. /root/uhuru_backup/uhuru.daily.sh Consider to put some "echo" commands into the script and direct them to a log file: log_file=/tmp/uhuru_daily_sh.log ... echo "Currently at: ..." >>$log_file ... This should give you an idea what part of the script causes the premature end. Thanks Thomas I confess, I've not originated scripts before and so am on a steep learning curve. Your suggestion was very useful but my implementation is poor. It did yield useful information though. It didn't find the exclude_list I created. I modified the script to point to it but clearly the syntax is not right # Good rsync options for uhuru_backups. rsync_opts="-av --exclude-from=exclude_list --delete --delete-excluded" # exclude list location: exclude_list=/root/uhuru_backup/exclude_list echo "Currently at line 17">>$log_file The log reported thus: /root/uhuru_backup/uhuru.daily.sh: line 17: $log_file: ambiguous redirect rsync: failed to open exclude file exclude_list: No such file or directory (2) rsync error: error in file IO (code 11) at exclude.c(1179) [client=3.1.1] Regards Clive -- Clive Menzies http://freecriticalthinking.org
Re: Crontab doesn't complete a script
Hi, > The daily backup script works fine when run manually as sudo but doesn't > complete when run as a root cronjob. The classic reason for this is difference in environment variables. I.e. the cron job could die from a non set variable. The classic remedy would be to set the missing variables inside the cronjob script. > /root/uhuru_backup/uhuru.daily.sh Consider to put some "echo" commands into the script and direct them to a log file: log_file=/tmp/uhuru_daily_sh.log ... echo "Currently at: ..." >>$log_file ... This should give you an idea what part of the script causes the premature end. Have a nice day :) Thomas