Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 28th August 2011, 09:09
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
Default Crontab does not run script?

Hi
I have got 2 NAS devices and I want to set up a nightly rsync backup from NAS1 to NAS2.

On NAS1 I have the rsync script working fine if I start it from command line.
(> /ffp/bin/snapshotMYBOOKWORLD.sh)
No problems with ssh password etc.

However, if I run the script via a crontab entry, I get rsync errors.
What causes the script to fail?

This is the rsync error I get
20110828_040508
rsync: Failed to exec ssh: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.5]
rsync: writefd_unbuffered failed to write 4 bytes [sender]: Broken pipe (32)
rsync error: error in IPC code (code 14) at io.c(1509) [sender=3.0.5]
20110828_040509
This is my crontab:
root@DLINK:~# crontab -l
32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &
5 2 * * * /ffp/bin/snapshot.sh
5 2 * * * /ffp/bin/snapshot.sh
5 4 * * * /ffp/bin/snapshotMYBOOKWORLD.sh
root@DLINK:~#
This is the backupscript
root@DLINK:~# ls -l /ffp/bin/snapshotMYBOOKWORLD.sh
-rwxrwxrwx 1 root root 806 Aug 21 11:56 /ffp/bin/snapshotMYBOOKWORLD.sh
Hope someone can help me!
Regards
Frank
Reply With Quote
Sponsored Links
  #2  
Old 29th August 2011, 16:16
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Do you use full paths in your script?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 29th August 2011, 22:00
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Not sure I use full paths ...

The funny thing is that the script runs fine when started from command line, but not when started via Crontab.

This is the backupscript:
# Set Source Path
# Back up the A drive (HD_a2) by identifying the source path as /mnt/HD_a2
# Back up multiple directories by surrounding a list with single quotes (i.e., s
# srcpath='/mnt/HD_a2/VIDEO /mnt/HD_a2/DOCUMENTEN /mnt/HD_a2/FOTOS /mnt/HD_a2/CO
srcpath='/mnt/HD_a2/DOCUMENTEN /mnt/HD_a2/VIDEO /mnt/HD_a2/FOTOS'

# Set the Destination Path
dstpath=root@192.168.178.100:/shares/internal/BACKUPNAS

ffppath=/ffp

datum=`date "+%Y%m%d_%H%M%S"`
echo $datum >> $ffppath/log/snapshotMYBOOKWORLD.log 2>&1

$ffppath/bin/rsync -av $srcpath $dstpath >> $ffppath/log/snapshotMYBOOKWORLD.log

datum=`date "+%Y%m%d_%H%M%S"`
echo $datum >> $ffppath/log/snapshotMYBOOKWORLD.log 2>&1
Reply With Quote
  #4  
Old 30th August 2011, 11:10
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You could use the full path for the date command (for example /bin/date). You can find that out by running
Code:
which date
Do the same for the echo command.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 1st September 2011, 06:55
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Got it solved!

The cause was indeed the paths.
I changed the rsync command into this and it works like a charm.

$ffppath/bin/rsync -av -e /ffp/bin/ssh $srcpath $dstpath >> $ffppath/log/snapshotMYBOOKWORLD.log 2>&1

Thanks for the hint!
Reply With Quote
  #6  
Old 1st September 2011, 07:02
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
Default

By the way, one less important thing i cant explain....

The crontab - l shows this:
root@DLINK:~# crontab -l
32 2 * * * /usr/sbin/rtc -s
30 2 2 * * /usr/sbin/rtc -c
59 1 * * * /usr/sbin/daylight &
5 2 * * * /ffp/bin/snapshot.sh
5 2 * * * /ffp/bin/snapshot.sh
5 4 * * * /ffp/bin/snapshotMYBOOKWORLD.sh

As you can see /ffp/bin/snapshot.sh is started twice ... how can this be?

Crontab is configured using this script:
#!/bin/sh

CRONTXT=/mnt/HD_a2/crontab.txt

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

# add the Rsync job to execute at 2:00 am
/bin/echo "5 2 * * * /ffp/bin/snapshot.sh" >> $CRONTXT
/bin/echo "5 4 * * * /ffp/bin/snapshotMYBOOKWORLD.sh" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT

Reply With Quote
Reply

Bookmarks

Tags
crontab rsync backup

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 09:26
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
Companion Script #2 for The Perfect Server - Fedora 13 x86_64 [ISPConfig 3]" MrCompTech Tips/Tricks/Mods 0 10th July 2010 05:11
Companion Script #1 for The Perfect Server - Fedora 13 x86_64 [ISPConfig 3]" MrCompTech Tips/Tricks/Mods 0 10th July 2010 05:09
crontab in detail sysconfig Suggest HOWTO 0 4th November 2006 10:38


All times are GMT +2. The time now is 10:15.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.