Page 1 of 1

Script runs in shell / CLI but not in cron? Cron script fail

Posted: 23 Oct 2012 01:08
by ponyslaystation
Hello

Seem to be having trouble getting by script to run in Cron.

this is my script:

Code: Select all

#!/bin/bash
mkdir /mnt/esatabackup
mount /dev/ada3p1 /mnt/esatabackup
rsync -azv --exclude-from '/mnt/pool1/Store/scripts/rsync/exclude.txt' --log-file=/mnt/pool1/Store/scripts/rsync/logs/rsync-`date "+%Y.%m.%d.%H.%M.%S."`txt /mnt/pool1/Store /mnt/esatabackup
umount /mnt/esatabackup
rm -r /mnt/esatabackup
This runs fine from a command prompt or when i click run now in cron.

my cron window looks like this:

Command: /mnt/pool1/Store/scripts/rsync/backup.sh
Description: bi weekly store backup (Wed $ Sun @ 8pm)
Who : root
minutes: 0
hours: 20
days: all
months: all
Week days: Sunday & Wednesday

I have checked the permissions on the script and they are all rwx...?

Cron is running, what am i missing? argh :(

Thanks

Re: Cron will not run my script?

Posted: 23 Oct 2012 08:00
by degen
Moin,

can you please try to use
Command: /bin/sh /mnt/pool1/Store/scripts/rsync/backup.sh

degen

Re: Cron will not run my script?

Posted: 23 Oct 2012 10:46
by daoyama
ponyslaystation wrote: Seem to be having trouble getting by script to run in Cron.
Cron uses very restricted PATH. This is not only NAS4Free. You have same path on FreeBSD.
If you want test from shell, set path.

if use csh:
# set path = (/etc /bin /sbin /usr/bin /usr/sbin)

if use bash (sh):
# PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin

Re: Cron will not run my script?

Posted: 23 Oct 2012 10:55
by alexey123
Why use bash for such small and simple script? Use sh

Code: Select all

#!/bin/sh

Re: Cron will not run my script?

Posted: 24 Oct 2012 12:38
by degen
Moin,

I like to make a short note on your script:

Currently, if the umount command fail - you will loose all files in /mnt/esatabackup
- there are some solutions beside adding some error handling to your script
- use rmdir instead of rm -r, rmdir only delete empty folders
- you may use '&&' to clue your commands together, only if the command1 run successful command2 will be executed
command1 && command2

degen

Re: Cron will not run my script?

Posted: 25 Oct 2012 03:35
by ponyslaystation
thanks people, will look into these helpful observations and get back to you. :)

CRON not launching task

Posted: 01 Nov 2012 19:08
by Faucon_2001
Hi,

I am trying to automatize my backup task using CRON without success.
My config is NAS4Free 9.1.0.1 (revision 394) x64-full; Nvidia ASUSACPI Intel(R) Core(TM)2 Duo CPU E7400 @ 2.80GHz 2046MiB RAM

In System / Advanced / CRON
Command : rsync -av --delete --log-file=/mnt/NAS/Echange/rsync.log /mnt/NAS /mnt/Backup
User : Root
Every day of the week, Every Month, Every Day, At 3:00 am

The command is working from the shell and also when I choose "Run Now", but CRON does not execute this task automatically.
What's wrong ?
Any clue ?

Philippe

Re: CRON not launching task

Posted: 01 Nov 2012 19:13
by daoyama
Faucon_2001 wrote: Command : rsync -av --delete --log-file=/mnt/NAS/Echange/rsync.log /mnt/NAS /mnt/Backup
I didn't check, but at least, you must specify the path of rsync like this:

/usr/local/bin/rsync -av (other options...)

Re: CRON not launching task

Posted: 01 Nov 2012 19:27
by Faucon_2001
Hi,

Thank you, it works with the full path :-)

Philippe