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 6th January 2013, 19:42
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
Default Script sun as other user than root doesn't via CRON

I have a NAS1 that makes a backup to another NAS2 using a scheduled rscync script which starts around 04:05.
NAS1 has a user account "backup" which is able to ssh to NAS2 using no password. (rsync uses ssh under water so this is convenient).
The script is started via a cron job.

However, when the script is run via cron, I get this error message:
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]

When I start the script as root, it all works fine.
Who understands what needs to be solved? Thanks very much!

The cron job entry is this:
Code:
root@DLINK:~# crontab -l
5 4 * * * /ffp/bin/snapshotMYBOOKWORLD.sh
This is the script:
Code:
root@DLINK:~# more /ffp/bin/snapshotMYBOOKWORLD.sh
#!/bin/sh

# Dit script is voor de MYBOOKWORLD
# User backup van de Dlink kan zonder password ssh naar user fweijers op de Mybookworld.

srcpath='/mnt/HD_a2/DOCUMENTEN /mnt/HD_a2/VIDEO/EIGEN* /mnt/HD_a2/FOTOS'

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

/ffp/bin/su -c "/ffp/bin/rsync -av $srcpath fweijers@192.168.178.100:/shares/internal/BACKUPNAS >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1" backup

datum=`date "+%Y%m%d_%H%M%S"` 
echo $datum >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1
root@DLINK:~#
As you can see, I used a "su -c <command> <username>" construction.
My thought was that there lies the problem …I was thinking of PATH settings for user backup, but those PATH settings seem ok:
Code:
root@DLINK:~# echo $PATH
/ffp/sbin:/usr/sbin:/sbin:/ffp/bin:/usr/bin:/bin
root@DLINK:~# su - backup
backup@DLINK:~$ echo $PATH
/ffp/bin:/usr/bin:/bin
backup@DLINK:~$ 

root@DLINK:~# ls -l /ffp/bin/ssh
-rwxr-xr-x    1 root     root       256336 May 19  2009 /ffp/bin/ssh
root@DLINK:~# ls -l /ffp/bin/rsync
-rwxr-xr-x    1 root     root       373820 Mar  3  2009 /ffp/bin/rsync

Last edited by fweijers; 8th January 2013 at 11:41. Reason: improved markup
Reply With Quote
The Following User Says Thank You to fweijers For This Useful Post:
aangelatexaxda9431 (13th February 2013)
Sponsored Links
  #2  
Old 16th January 2013, 07:38
fweijers fweijers is offline
Junior Member
 
Join Date: Aug 2009
Posts: 13
Thanks: 0
Thanked 3 Times in 3 Posts
 
Default Solved

just add a PATH setting to the script run by crontab and all is good.
Code:
 export PATH=/ffp/sbin:/ffp/bin:$PATH
Reply With Quote
The Following User Says Thank You to fweijers For This Useful Post:
falko (18th January 2013)
Reply

Bookmarks

Tags
cron, rsync, ssh, user

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
apache log issues abubin General 13 1st August 2010 17:47
automatic webmail link admins Installation/Configuration 16 22nd June 2009 16:42
messed up apache2-php5 installation klonos HOWTO-Related Questions 2 24th January 2009 23:12
monit howto Jamesk5 HOWTO-Related Questions 11 5th August 2008 15:10
cannot connect to ispconfig guidovanh Installation/Configuration 22 3rd March 2006 19:52


All times are GMT +2. The time now is 22:38.


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