Script sun as other user than root doesn't via CRON

Discussion in 'Programming/Scripts' started by fweijers, Jan 6, 2013.

  1. fweijers

    fweijers New Member

    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]
    :confused:
    When I start the script as root, it all works fine.:D
    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 [email protected]:/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: Jan 8, 2013
  2. fweijers

    fweijers New Member

    Solved

    just add a PATH setting to the script run by crontab and all is good.
    Code:
     export PATH=/ffp/sbin:/ffp/bin:$PATH  
     

Share This Page