Rsync works in shell but not in cron


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Rsync works in shell but not in cron
# 1  
Old 11-23-2011
Rsync works in shell but not in cron

So I have this rsync script I wrote to grab some sql files and import them to a database. I left in the mysql stuff just give context to the situation. The real problem is with my rsync code.

script.sh (chmod 744)
Code:
#!/bin/sh
rsync -av --rsh="sshpass -p'PASSWORD' ssh -l'USERNAME'" WEBSITE.com:/PATH/TO/RSYNC/REMOTE /PATH/TO/RSYNC/LOCAL
tables=(TABLE1 TABLE2)
for name in ${tables[@]}
do
mysql -u'USER' -p'PASSWORD' DBNAME < PATH/TO/SQLFILES/$name.sql
done

My cron looks like this ...

Code:
0 * * * * /PATH/TO/SCRIPT/script.sh

Here's the problem. When I execute the script in bash, it works fine. But my cron job returns these errors

Code:
rsync: Failed to exec sshpass: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(84) [receiver=3.0.6]
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [receiver=3.0.6]

I don't get it, why would the script work in bash but not in cron ? What am I doing wrong ? Smilie

Thanks Smilie
# 2  
Old 11-23-2011
Hi,
May you try to reference the full path to sshpass in the 2nd line? (you can use
Code:
which sshpass

to find tghe full path).

Code:
rsync -av --rsh="/path/to/sshpass -p'PASSWORD' ssh -l'USERNAME'" WEBSITE.com:/PATH/TO/RSYNC/REMOTE /PATH/TO/RSYNC/LOCAL

Let us know how it goes
see ya
fra
# 3  
Old 11-23-2011
That worked ! Thanks frappa !
# 4  
Old 11-23-2011
Glad to hear that!

The hint to the problem root cause was given by:
Code:
rsync: Failed to exec sshpass: No such file or directory (2)

The explanation should be that, when executed from crontab, the environment initialization files (.bashrc, .bash_profile, etc) are not read, so that the PATH variable is not initialized with the path of the sshpass executable.

see ya
fra
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

2. AIX

Cron job not working but works on other nodes.

Hi All, I have a many cron jobs scheduled in my AIX server. Only one cron not getting executed in the same server but that job is good on all other servers. Here is my cron , which will keep last 30 files and remove others., 00 00 * * * /usr/bin/find /tmp/reports/nmon -name *.nmon -mtime... (9 Replies)
Discussion started by: Thala
9 Replies

3. Shell Programming and Scripting

s3cmd works on command line not on cron

Ubuntu 9.10 is my linux distro Based on forums they say that the problem is with environment . here is my case: login as user, then sudo -s using this command: s3cmd put file s3://bucket >>worked! now here is the simple script intended for testing: #! /bin/bash env >/tmp/cronjob.log... (1 Reply)
Discussion started by: qwerty20
1 Replies

4. Shell Programming and Scripting

find cmd works different on cron job ?

/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime $DAYS_AGO -printf %f -printf "\n" | sort -r > $FILES The above command gives different results when run on a cron job. When run manually the result is accurate. (2 Replies)
Discussion started by: nuthalapati
2 Replies

5. Shell Programming and Scripting

Script works but doesn't with cron

Good morning, The script below without the hilited text successfully FTPs the files in question to the other server when it is called from the crontab. I don't want to establish an FTP connection when there are no files so I tried including the hilited lines to only establish an FTP connection... (6 Replies)
Discussion started by: philplasma
6 Replies

6. UNIX for Dummies Questions & Answers

Problems using rsync with cron

Hi, I've created a cron job for a script with a rsync command in it. The script is named pull.sh and contains the following line : What it is supposed to do is pull backup files from the production server of my company to my local server. It should also generate the log file (output.log)... (1 Reply)
Discussion started by: anaigini45
1 Replies

7. UNIX for Advanced & Expert Users

FTP run by cron only works if user logged in?

I set up a cron job to FTP to another machine. If I have not logged in before the time the cron is set to run, then the ftp program won't connect. I have run this cron on other boxes (diff networks) and it works fine...it is just this one. If anyone has any suggestions as to what would be... (5 Replies)
Discussion started by: vincaStar
5 Replies

8. UNIX for Advanced & Expert Users

Rsync via cron

Hi, I am running a rsync via cron job. Its running fine and is scheduled to 9:00 AM everyday. Sometimes it runs for more than 24 hours, such that the next days cron also fires. Now how will the sync happen as the <sync file> that both crons have created might conflict. Thanks (5 Replies)
Discussion started by: vibhor_agarwali
5 Replies

9. UNIX for Dummies Questions & Answers

Works Manually - not in CRON

I've got a ksh script that works like a charm when I run it manually. When I set it up in a cron, I keep getting this error in my log: syntax error at line 90: `$' unexpected Here's my snippet of code starting at line 90: while ] do sleep 900 done What's the... (5 Replies)
Discussion started by: dstinsman
5 Replies

10. UNIX for Dummies Questions & Answers

use rsync by cron

Hi there: I run rsync very well by typing: rsync -avz /source /destination Then I want to run it by cron. So I had a crontab file like this: * * * * * rm file * * * * * rsync -avz /source /destination > cron_result (The first line is used to test whether cron is working.) When I check... (0 Replies)
Discussion started by: Steven.surfboy
0 Replies
Login or Register to Ask a Question