Latest News:
*New 11.2 series Release:
2019-06-20: XigmaNAS 11.2.0.4.6766 - released!

*New 12.0 series Release:
2019-06-20: XigmaNAS 12.0.0.4.6766 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

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

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
ponyslaystation
NewUser
NewUser
Posts: 5
Joined: 08 Oct 2012 03:14
Status: Offline

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

#1

Post by ponyslaystation » 23 Oct 2012 01:08

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
Last edited by al562 on 31 Dec 2012 04:05, edited 2 times in total.
Reason: Adjusted Subject.

degen
Status: Offline

Re: Cron will not run my script?

#2

Post by degen » 23 Oct 2012 08:00

Moin,

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

degen

User avatar
daoyama
Developer
Developer
Posts: 423
Joined: 25 Aug 2012 09:28
Location: Japan
Status: Offline

Re: Cron will not run my script?

#3

Post by daoyama » 23 Oct 2012 10:46

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
NAS4Free 10.2.0.2.2115 (x64-embedded), 10.2.0.2.2258 (arm), 10.2.0.2.2258(dom0)
GIGABYTE 5YASV-RH, Celeron E3400 (Dual 2.6GHz), ECC 8GB, Intel ET/CT/82566DM (on-board), ZFS mirror (2TBx2)
ASRock E350M1/USB3, 16GB, Realtek 8111E (on-board), ZFS mirror (2TBx2)
MSI MS-9666, Core i7-860(Quad 2.8GHz/HT), 32GB, Mellanox ConnectX-2 EN/Intel 82578DM (on-board), ZFS mirror (3TBx2+L2ARC/ZIL:SSD128GB)
Develop/test environment:
VirtualBox 512MB VM, ESXi 512MB-8GB VM, Raspberry Pi, Pi2, ODROID-C1

User avatar
alexey123
Moderator
Moderator
Posts: 1568
Joined: 19 Aug 2012 08:22
Location: Israel, Karmiel
Contact:
Status: Offline

Re: Cron will not run my script?

#4

Post by alexey123 » 23 Oct 2012 10:55

Why use bash for such small and simple script? Use sh

Code: Select all

#!/bin/sh
Home11.0.0.4 - Sayyadina (revision 4249)/ x64-embedded on SAPPHIRE Pure Mini E350 / 8G RAM / UPS Ippon Back Power Pro 600
Lab 10.2.0.2 - Prescience (revision 2545) /x64-embedded on Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz / H61M-DS2 / 4G RAM / UPS Ippon Back Power Pro 600
New XigmanasXigmaNAS version 11.2.0.4.6026 on x64-embedded on AMD A8-7600 Radeon R7 A88XM-PLUS/ 16G RAM
TEST1 11.0.0.4 - Pilingitam (revision 4333) bpi-embedded on Allwinner a20 / 1015MiB RAM

degen
Status: Offline

Re: Cron will not run my script?

#5

Post by degen » 24 Oct 2012 12:38

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

ponyslaystation
NewUser
NewUser
Posts: 5
Joined: 08 Oct 2012 03:14
Status: Offline

Re: Cron will not run my script?

#6

Post by ponyslaystation » 25 Oct 2012 03:35

thanks people, will look into these helpful observations and get back to you. :)

Faucon_2001
NewUser
NewUser
Posts: 5
Joined: 01 Nov 2012 17:54
Status: Offline

CRON not launching task

#7

Post by Faucon_2001 » 01 Nov 2012 19:08

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

User avatar
daoyama
Developer
Developer
Posts: 423
Joined: 25 Aug 2012 09:28
Location: Japan
Status: Offline

Re: CRON not launching task

#8

Post by daoyama » 01 Nov 2012 19:13

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...)
NAS4Free 10.2.0.2.2115 (x64-embedded), 10.2.0.2.2258 (arm), 10.2.0.2.2258(dom0)
GIGABYTE 5YASV-RH, Celeron E3400 (Dual 2.6GHz), ECC 8GB, Intel ET/CT/82566DM (on-board), ZFS mirror (2TBx2)
ASRock E350M1/USB3, 16GB, Realtek 8111E (on-board), ZFS mirror (2TBx2)
MSI MS-9666, Core i7-860(Quad 2.8GHz/HT), 32GB, Mellanox ConnectX-2 EN/Intel 82578DM (on-board), ZFS mirror (3TBx2+L2ARC/ZIL:SSD128GB)
Develop/test environment:
VirtualBox 512MB VM, ESXi 512MB-8GB VM, Raspberry Pi, Pi2, ODROID-C1

Faucon_2001
NewUser
NewUser
Posts: 5
Joined: 01 Nov 2012 17:54
Status: Offline

Re: CRON not launching task

#9

Post by Faucon_2001 » 01 Nov 2012 19:27

Hi,

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

Philippe

Post Reply

Return to “Scripts and shell tips”