View Single Post
Old 6th January 2013, 19:42
fweijers fweijers is offline
Junior Member
Join Date: Aug 2009
Posts: 11
Thanks: 0
Thanked 2 Times in 2 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:
root@DLINK:~# crontab -l
5 4 * * * /ffp/bin/
This is the script:
root@DLINK:~# more /ffp/bin/

# 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@ >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1" backup

datum=`date "+%Y%m%d_%H%M%S"` 
echo $datum >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1
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:
root@DLINK:~# echo $PATH
root@DLINK:~# su - backup
backup@DLINK:~$ echo $PATH

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
Sponsored Links