UPDATE: Script A updated to reflect declaration of paths to sshpass, scp, per paxdiablo and Evert. Because this does not fix the problem, I do not believe the question is a duplicate of the linked question.
I have a bash script, let's call it A, that finds files created more than 15 minutes ago and moves them from Server 1 to Server 2. The code for A is:
#!bin/bash
find /data/Output/*.txt -mmin +15 -exec /usr/local/bin/sshpass -p 'thepassword' /usr/bin/scp -c blowfish "{}" Server2:/data/Output \;
If I run the code from the command line, it moves the data. If, however, I create a crontab file that calls the script, it does not run.
The crontab script reads:
0 * * * * R CMD BATCH /home/me/generate_data.txt
15 * * * * /bin/bash /home/me/move_data.sh > /dev/null 2>&1
To have cron call the script, I type:
crontab /path/to/crontab/file.txt
crontab -l shows the job is running. I also know cron itself is running because generate_data.txt downloads data every hour like it should. The problem thus does not appear to be cron or bash in isolation but something about them working together.
This problem seems common, but suggestions here, here, and here have not helped. I have tried:
- Permissions. Permissions on both files are 755.
- Put it /etc/cron.hourly/ without .txt ending.
- Add an empty line at the end of the file.
- Call "bash" and "/bin/bash".
- Restarting cron.
I edit this script using nano. Server A is Ubuntu 14.04 LTS, Server B is an Amazon Linux AMI. Both are hosted at Amazon Web Services.
EDIT: I should add that I have this process running between a third server and Server B and it works fine, i.e. send files from Server C to B using these scripts. Server C is Ubuntu 12.02 LTS, Server A Ubuntu 14.04 LTS.
What am I missing?