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-09-20 01:34:34

stevelucky
Member
Registered: 2010-09-14
Posts: 15

Disappearing cronjob?

I have been beating my head against a wall for a few days and am no closer to an answer now, than I was then. Admittedly, I'm quite the linux newbie, but I've learned a lot in the past couple weeks but none of it is helping me right now.

I have two drives in my DNS-323. My HD_a2 has all my data and I want to set up a cronjob to back that data up nightly to my HD_b2. I followed all the instructions here: http://dns323.kood.org/forum/viewtopic. … 50&p=1. It was pretty straightforward and after a few attempts, I actually got the cronjob to run and back up all my data. However, I haven't been able to get it to run since. When I reboot my 323, I run, crontab -l and I get the following:

Code:

59 1 * * * /usr/sbin/daylight&
30 2 * * * /usr/sbin/stime&
32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
1 15 * * * /mnt/HD_a2/ffp/bin/rsync -av --delete --backup --backup-dir=../backup_rsync_save/2010-09-19 /mnt/HD_a2/* /mnt/HD_b2/rsync_save >> /mnt/HD_a2/ffp/log/rsync.last.log 2>&1

I see my cronjob scheduled and all is well. And then, when the time comes for the job to run, it won't run and if I run crontab -l again, the job will no longer be there and this is what i get:

Code:

59 1 * * * /usr/sbin/daylight&
30 2 * * * /usr/sbin/stime&
32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c

I thought it might be a permissions thing, but I'm not sure how that could be the issue. What would cause a scheduled cronjob to just disappear?

A couple other interesting pieces of information, if I reboot the 323, and run crontab -l, I can see it listed, but as soon as I click on the shared drive to access the 323 from my computer, I'll immediately run crontab -l and the cronjob will be gone. The same goes for logging into the 323 via the web interface. As soon as I do that, the cronjob disappears as well. So, it looks like logging into the DND-323 via a browser, accessing the drive via my computer  or allowing it the cronjob run will as all delete the cronjob.

I sure would appreciate some help with this.

Last edited by stevelucky (2010-09-20 01:35:12)

Offline

 

#2 2010-09-20 14:57:42

index monkey
Member
From: UK
Registered: 2007-06-14
Posts: 112

Re: Disappearing cronjob?

Hi stevelucky,

have a look at the following thread http://dns323.kood.org/forum/t265-littl … ccess.html

cron jobs will get lost following a reboot, thus a script is used to set up the cron jobs once the dns-323 restarts.
I use the so called "time machine" backup in my signature, maybe that would give you better results.

good lucky


DNS-323, HW B1, 2 x 2TB WD green, fw 1.08, fun_plug 0.5, transmission, automatic, nzbget newsreader & rsync time machine backup.

Offline

 

#3 2010-09-20 18:23:26

stevelucky
Member
Registered: 2010-09-14
Posts: 15

Re: Disappearing cronjob?

Yeah, maybe the time machine backup is a little more of what I need. One question though, since I've already run the backup using my first cronjob, will I need to back up that data all over again? It's almost 1TB of data so I'd rather not have to run it all over again. Or will it see that the data is already there and just look for changes?

Offline

 

#4 2010-09-20 19:31:46

stevelucky
Member
Registered: 2010-09-14
Posts: 15

Re: Disappearing cronjob?

Actually, this doesn't fix my problem. I set everything up, just as you had outlined. I reboot my 323, and I can see the cronjob, by running crontab -l. As soon as I log in to the 323 interface, the cronjob disappears (I confirm this by running crontab -l, again). Or if I access it via the finder, it disappears as well. Why would accessing the 323 cause the cronjob to disappear?

Offline

 

#5 2010-09-20 20:04:11

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Disappearing cronjob?

I had the same issue. It seems it is a timing issue on boot up.

I inserted a 3 minute delay '/ffp/bin/sleep 3m' into my addcron script and it worked perfectly. May help you too.


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#6 2010-09-20 20:18:37

stevelucky
Member
Registered: 2010-09-14
Posts: 15

Re: Disappearing cronjob?

I'll give that a shot. So, where should I put that in the script? Does it matter where it's placed?

So, like this?

Code:

#!/bin/sh

CRONTXT=/mnt/HD_a2/crontab.txt

# start with existing crontab
/bin/crontab -l > $CRONTXT

# wait 3 minutes before running the script
/ffp/bin/sleep 3m

# 1. add the Rsync job to execute at 2:05 am 2. Create a logfile (append to any existing log file) 3. Create a backup directory on Vol_B for deleted files
# note: use a single > after /mnt/HD_b2 if you want to a create a new log file each night with no append

/bin/echo "45 10 * * * /mnt/HD_a2/ffp/bin/rsync -av --delete --backup --backup-dir=../backup_rsync_save/`date +%Y-%m-%d` /mnt/HD_a2/* /mnt/HD_b2/rsync_save >> /mnt/HD_a2/ffp/log/rsync.last.log 2>&1" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT

Last edited by stevelucky (2010-09-20 20:24:34)

Offline

 

#7 2010-09-20 21:07:35

stevelucky
Member
Registered: 2010-09-14
Posts: 15

Re: Disappearing cronjob?

FunFiler wrote:

I had the same issue. It seems it is a timing issue on boot up.

I inserted a 3 minute delay '/ffp/bin/sleep 3m' into my addcron script and it worked perfectly. May help you too.

That did it! Thank you so much.

Offline

 

#8 2010-09-21 02:42:24

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Disappearing cronjob?

No problem, glad it worked. BTW - it doesn't really matter where you put it in the script as long as it is before

# install the new crontab
/bin/crontab $CRONTXT

To cover the unlikely event that something else goes on, I'd suggest moving it above
# start with existing crontab
/bin/crontab -l > $CRONTXT


On another note, I found a way to set this up so that I can edit and rerun the script numerous times to test it out. Without any changes, you will duplicate the new cron entries, which obviously would not be good.


What you can do, is run 'crontab -l' on its own and count the number of default lines (it changes depending on what options / configuraiton you have). Between my 2 NAS units, it is either 5 or 6 (one is Raid 1 and the other is independant drives). Then modify the line that saves the cron entries as follows:

/bin/crontab -l|head -n 5 > $CRONTXT

Change the "5" above to the number of lines. This will strip out any extra entries before appending the new ones allowing you to run the script as many times as required to test different settings etc.


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#9 2010-09-21 18:15:36

karlrado
Member
Registered: 2009-12-07
Posts: 229

Re: Disappearing cronjob?

It is sort of odd that the sleep is needed.  I suppose that some other process is running in the background during init that starts in the background.  Oh, I see:  In /etc/rc.sh there is an invocation of "crond", which would cause the cron daemon to start running, which probably includes loading the default crontab.  It may not finish loading the default crontab before calling the user fun_plug.

I've got a pretty long fun_plug script and I modify my crontab at the very end of it, so I think I've been lucky so far, as far as the timing goes.  I must be doing enough stuff in my fun_plug to allow crond to finish loading the default crontab before I change it.

Although sleeping is OK, I wonder if a more robust solution is possible.  Maybe go into a loop, reading the crontab with "crontab -l" until it returns some output?  Then set the new crontab.


DNS-323 FW 1.07 : 2 1TB WD Caviar Green SATA : fun_plug: utelnet + optware (no ffp)

Offline

 

#10 2010-09-21 21:09:04

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Disappearing cronjob?

I'm sure you could get really fancy, but personally I only reboot every couple of months so a 3 minute delay is no big deal. Also, my jobs run at night so as long as I reboot in the day it is just fine.

The ability to edit the script and rerun it without rebooting is more important to me and that is why the "head" command helps in my situation more than the sleep.

Last edited by FunFiler (2010-09-21 21:10:11)


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#11 2011-12-13 00:02:15

esebag
Member
Registered: 2008-01-28
Posts: 60

Re: Disappearing cronjob?

I'm having the same problem as Stevelucky- adding '/ffp/bin/sleep 3m' doesnt seem to be doing the trick sad

here's my script :
----------------------------------------

#!/bin/sh

# wait 3 minutes before running the script
/ffp/bin/sleep 3m

CRONTXT=/mnt/HD_a2/crontab.txt

# install the new crontab
/bin/crontab $CRONTXT

# start with existing crontab
/bin/crontab -l > $CRONTXT


#add backup specific folders of Volume_1 (/mnt/HD_a2) to Volume_2 (/mnt/HD_b2) at
/bin/echo "15 15 * * * /ffp/bin/rsync -av -delete /mnt/HD_a2/testt /mnt/HD_b2/testt" >> $CRONTEXT


# clean up
/bin/rm $CRONTXT

Offline

 

#12 2011-12-13 07:02:35

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

Re: Disappearing cronjob?

This script only sleeps, writes stuff to a file which is later deleted, it doesnt modify crontab.

Offline

 

#13 2011-12-13 18:45:42

esebag
Member
Registered: 2008-01-28
Posts: 60

Re: Disappearing cronjob?

Any tips on how to modify crontab so that my rsync task stays??

Offline

 

#14 2011-12-13 22:11:54

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

Re: Disappearing cronjob?

#!/bin/sh

# wait 3 minutes before running the script
/ffp/bin/sleep 3m

CRONTXT=/mnt/HD_a2/crontab.txt

# install the new crontab
/bin/crontab $CRONTXT

# start with existing crontab
/bin/crontab -l > $CRONTXT


#add backup specific folders of Volume_1 (/mnt/HD_a2) to Volume_2 (/mnt/HD_b2) at
/bin/echo "15 15 * * * /ffp/bin/rsync -av -delete /mnt/HD_a2/testt /mnt/HD_b2/testt" >> $CRONTXT

/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT

Last edited by bjby (2011-12-13 22:13:09)

Offline

 

#15 2011-12-13 23:24:05

esebag
Member
Registered: 2008-01-28
Posts: 60

Re: Disappearing cronjob?

Thanks. Unless i misunderstand your intentions you did a copy/paste of my last script. Am i missing anything else? smile

Offline

 

#16 2011-12-15 21:48:30

karlrado
Member
Registered: 2009-12-07
Posts: 229

Re: Disappearing cronjob?

He added a line after the backup line was appended to the crontab file that would reload the modified crontab file.

That being said, I still don't think it is right. 

The lines:

# install the new crontab
/bin/crontab $CRONTXT

shouldn't be done before the file $CRONTXT is created.  Crontab just reports an error about a missing file and leaves the in-memory crontab alone, so no harm.

How about:

#!/bin/sh

# wait 3 minutes before running the script
/ffp/bin/sleep 3m

CRONTXT=/mnt/HD_a2/crontab.txt

# Write out the original DLink firmware crontab
/bin/crontab -l > $CRONTXT

#add backup specific folders of Volume_1 (/mnt/HD_a2) to Volume_2 (/mnt/HD_b2) at
/bin/echo "15 15 * * * /ffp/bin/rsync -av -delete /mnt/HD_a2/testt /mnt/HD_b2/testt" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT


Untested....


DNS-323 FW 1.07 : 2 1TB WD Caviar Green SATA : fun_plug: utelnet + optware (no ffp)

Offline

 

#17 2011-12-15 22:35:27

esebag
Member
Registered: 2008-01-28
Posts: 60

Re: Disappearing cronjob?

Tnx, I'll test it out and let you know.

Offline

 

#18 2011-12-30 06:07:55

esebag
Member
Registered: 2008-01-28
Posts: 60

Re: Disappearing cronjob?

Tnx, it survived the reboot- it works. yay!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB