DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-02-25 21:07:24

stutuff
Member
Registered: 2010-02-25
Posts: 8

backup to USB fails under cron

I am new to Linux and scripting. I have a DNS-323 w/funplug 0.5

I created a script that backs up folders on the hard drive to a USB drive. It works running manually but fails when I try to run the script through cron.

12 3 * * 1-5 /mnt/HD_a2/scripts/backup_dlink00.sh

Because the USB drive might connect to any /dev/sxx (depending on what else has been mounted at the time) I wanted to look for a specific drive at backup time and see where it was connected and use that information to mount the drive. I have labeled my backup drives "DLINKBKUP00" and use:

DEVNODE=$(blkid -t LABEL=DLINKBKUP00 | awk -F: '{print $1}')

to see if the disk is there and take the connection part I need for mounting the drive.

The problem is that blkid returns an error 127 (-1) when the script is run from cron. The script works just fine from the command line.

Attached is the entire script...a little help would be great!


Attachments:
Attachment Icon backup_dlink00.sh, Size: 2,054 bytes, Downloads: 211

Offline

 

#2 2010-02-26 18:38:36

crs2027
Member
Registered: 2008-10-14
Posts: 46

Re: backup to USB fails under cron

I found the path to be an issue when using cron.

For example when calling awk or grep I had to either add the path to the script, or use CMDGREP=/mnt/HD_a2/ffp/bin/grep" then use the command by calling $CMDGREP instead.. obviously same for awk.

Last edited by crs2027 (2010-02-26 18:40:41)

Offline

 

#3 2010-02-28 16:58:51

stutuff
Member
Registered: 2010-02-25
Posts: 8

Re: backup to USB fails under cron

I don't even think it is getting to the 'awk' command. I tried a simple script:

#!/bin/sh
# Author: Stu Schechter

NOW=$(date +"%b-%d-%y")
LOGFILE="/mnt/HD_a2/scripts/backuplog-$NOW.log"

date >> $LOGFILE
blkid >> $LOGFILE

exit 0

the DATE showed up in the logfile but blkid showed nothing.

Can cron have trouble finding/using 'blkid'?

Offline

 

#4 2010-02-28 19:35:06

bjby
Member
Registered: 2009-02-22
Posts: 265

Re: backup to USB fails under cron

The PATH might be set differently when running in cron. You can verify this by echoing $PATH to a file.

A simple workarond as described above, is to always use fullpath to all commands.

/ffp/bin/date
/ffp/sbin/blkid
/ffp/bin/awk
etc...

Another is to set the PATH correctly.

Last edited by bjby (2010-02-28 19:36:18)

Offline

 

#5 2010-03-01 04:12:03

stutuff
Member
Registered: 2010-02-25
Posts: 8

Re: backup to USB fails under cron

That was it. Specifying full paths did the trick...thanks for helping a newbie!

I looked at $PATH and it shows:

/ffp/sbin:/ffp/bin:other paths...

These are the correct paths so why does cron not seem to get it?

Offline

 

#6 2010-03-01 08:02:32

bjby
Member
Registered: 2009-02-22
Posts: 265

Re: backup to USB fails under cron

This is why, (I think, might be wrong)

When you login the /ffp/etc/profile script is run, it sets the path variable.

I the environment cron i running this profile script has not been executed, thereby the path variable is different.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB