0

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?

Community
  • 1
  • 1
ZacharyST
  • 658
  • 2
  • 6
  • 22
  • The PATHway to solving this one is muddy :-) Or see http://stackoverflow.com/questions/1068071/include-path-and-cron/1068084#1068084 for a less Jedi answer. Or, better yet, search first and try *every* suggestion: http://stackoverflow.com/search?q=user%3A14860+path+cron :-) You could also try sending the cron output to `/tmp/lookatme` rather than `/dev/null`, at least temporarily. – paxdiablo Jun 01 '16 at 05:48
  • I've seen people mention setting a PATH variable, such as here (http://askubuntu.com/questions/264607/bash-script-not-executing-from-crontab), but I don't understand what that means or how to fix it. 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. – ZacharyST Jun 01 '16 at 05:51
  • If PATH happens to be the underlying issue, then specify the *full* paths to `scp` and `sshpass` in the line in your script. –  Jun 01 '16 at 05:57
  • Hi Evert, thank you for the clarification. I've updated the script, and it still does not work. I updated the question to reflect this. – ZacharyST Jun 02 '16 at 06:05
  • Add the line "exec >> /tmp/some-file 2>&1" to your script after the #! line. This will redirect standard output & standard error to /tmp/some-file. After cron runs the script, inspect /tmp/some-file to see if the script is outputting any error messages. – Kenster Jun 03 '16 at 20:17

0 Answers0