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 2009-04-02 21:13:37

savva
Member
Registered: 2009-04-02
Posts: 5

RSYNC and Cron executing script

Hey Guys,

I'm trying to setup a cron job on my 323 to run a script. The reason why i want to use a script is so that i only have to change the script and not have to worry about reloading the cron file and editing it all the time.

When i run the script which is called nightly-run it works, but when i try to put it as a cron service it doesn't work. The nightly-run is set to full permissions (777). Does anybody have any ideas i can try????

Here is my output of crontab -l

32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &
5 13 * * * /mnt/HD_a2/nightly-run &

Here is the script in nightly-run

#!/bin/sh
rsync -arptv --delete /mnt/HD_a2/Live/ /mnt/HD_b2/Backup/Live/ > /mnt/HD_a2/rsync.Live.log
rsync -arptv --delete /mnt/HD_a2/Backup/ /mnt/HD_b2/Backup/Backup/ > /mnt/HD_a2/rsync.Backup.log

Here is what my editcron.sh looks like:

#!/bin/sh
CRONTXT=/mnt/HD_a2/crontab.txt

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

# Runs daily 1:05pm -
/bin/echo "5 13 * * * /mnt/HD_a2/nightly-run &" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# Clean up the mess
/bin/rm $CRONTXT


Thanks,
Savva

Offline

 

#2 2009-04-02 21:38:03

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: RSYNC and Cron executing script

Try using the full path to the rsync executable, something like:

   /ffp/bin/rsync

in the nightly-run script.


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#3 2009-04-03 00:11:35

savva
Member
Registered: 2009-04-02
Posts: 5

Re: RSYNC and Cron executing script

Hey Mig,

I tried that out, but it didnt work sad

Any other suggestions....i've been trying to get this to work for so long and i cant figure out what i'm doing wrong!

Offline

 

#4 2009-04-03 00:57:45

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: RSYNC and Cron executing script

How about creating a log file for the 'nightly-run' cron job, like this:

In the editcron.sh

  /bin/echo "5 13 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly_run.log &" >> $CRONTXT

output of crontab -l should be:

32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &
5 13 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly_run.log &


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#5 2009-04-04 21:54:20

savva
Member
Registered: 2009-04-02
Posts: 5

Re: RSYNC and Cron executing script

OK it looks like my crontab is not running....at the very least the file nightly_run.log should of been created.

Here is what my crontab looks like:
root@NAS:/mnt/HD_a2# crontab -l
32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &
45 14 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly-run.log &

here is the output of the date command as well:
Sat Apr  4 14:50:30 DST 2009

note: reloaded the changes at 2:40 so i gave it 5 mins to run.

This is what a cat of my ffp.log file looks like

**** fun_plug script for DNS-323 (2008-08-11 tp@fonz.de) ****
Sat Apr  4 13:25:57 GMT 2009
ln -snf /mnt/HD_a2/ffp /ffp
* Running /ffp/etc/fun_plug.init ...
* Running /ffp/etc/rc ...
* /ffp/start/syslogd.sh inactive
* /ffp/start/SERVERS.sh inactive
* /ffp/start/portmap.sh inactive
* /ffp/start/unfsd.sh inactive
* /ffp/start/nfsd.sh inactive
* /ffp/start/ntpd.sh inactive
* /ffp/start/smartd.sh inactive
* /ffp/start/LOGIN.sh inactive
* /ffp/start/telnetd.sh inactive
* /ffp/start/sshd.sh ...
Starting /ffp/sbin/sshd
* /ffp/start/rsyncd.sh inactive
* /ffp/start/mediatomb.sh inactive
* /ffp/start/kickwebs.sh inactive
* /ffp/start/lighttpd.sh inactive
* /ffp/start/inetd.sh inactive
* /ffp/start/editcron.sh ...
*  OK

It looks like my editcrong is not running

Here is an output of my edit cron.sh file
#!/bin/sh
CRONTXT=/mnt/HD_a2/crontab.txt

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

# Runs daily 2:05am -
/bin/echo "35 14 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly-run.log &" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# Clean up the mess
/bin/rm $CRONTXT

Permission on this file is
-rwxr-xr-x    1 root     root          300 Apr  4 14:24 editcron.sh

Offline

 

#6 2009-04-05 11:23:38

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: RSYNC and Cron executing script

O.K. I'm a bit confused with your last post..., you state "It looks like my editcrong is not running"
but the ffp.log has an entry "* /ffp/start/editcron.sh ..."

First, make sure your DNS-323 clock agrees with your wall clock.
that could really mess up any debugging of cron tasks.

Next, add some debug print statements to editcron.sh to verify editcron.sh
is executing correctly.  These print statements will appear in ffp.log.

to the beginning of editcron.sh, add:
   echo -n  "Starting $0 at "
   date

and to the end of editcron.sh, add:

   echo "Changed crontab to:"
   /bin/crontab -l

the new editcron.sh (with debug print statements) should look like this

Code:

#!/bin/sh

# Debug print statements
echo -n  "Starting $0 at "
date

CRONTXT=/mnt/HD_a2/crontab.txt

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

# Runs daily 2:05am -
/bin/echo "35 14 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly-run.log &" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# Clean up the mess
/bin/rm $CRONTXT

# Debug print statements
echo "Changes crontab to:"
/bin/crontab -l

Then restart your DNS-323 and look at the output of ffp.log, if you see the new debug print statements
then you know the editcron.sh script is executing correctly.

If editcron.sh is executing correctly, then you have to figure out why the nightly-run.log is not being created.

Last edited by mig (2009-04-05 11:24:56)


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#7 2009-04-06 21:51:00

savva
Member
Registered: 2009-04-02
Posts: 5

Re: RSYNC and Cron executing script

Well good news i got it working big_smile .... so here's what my scripts look like

Future expansion i'm going to create is emailing log files smile

---------------------------------------------
Editcron.sh
#!/bin/sh
CRONTXT=/mnt/HD_a2/crontab.txt

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

# Runs daily 2:05am -
/bin/echo "45 20 * * * /mnt/HD_a2/nightly-run > /mnt/HD_a2/nightly-run.log 2>&1" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# Clean up the mess
/bin/rm $CRONTXT
----------------------------------------

Nightly-run
#!/bin/sh

/mnt/HD_a2/ffp/bin/rsync -arptv --delete /mnt/HD_a2/Live/ /mnt/HD_b2/Backup/Live/ > /mnt/HD_a2/rsync.Live.log

/mnt/HD_a2/ffp/bin/rsync -arptv --delete /mnt/HD_a2/Backup/ /mnt/HD_b2/Backup/Backup/ > /mnt/HD_a2/rsync.Backup.log

Offline

 

#8 2009-04-06 22:00:07

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: RSYNC and Cron executing script

So, the problem turned out to be not using the full path to the rsync command in
the nightly-run.sh?

Last edited by mig (2009-04-06 22:00:32)


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#9 2009-04-06 22:41:37

savva
Member
Registered: 2009-04-02
Posts: 5

Re: RSYNC and Cron executing script

Either that or adding in the 2>&1 in the editcron.sh file

I changed both thoes options at the same time so i'm not sure which one fixed it. I was happy it worked i didnt care to try and see which one it was lol .... I Will try in a day or two and let everybody know which one it was

Thanks for the help, it was appreciated

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB