0

On a CentOS 7.2 server the following command runs successfully manually -

scp usrname@storage-server:/share/Data/homes/AWS/2301KM-$(date +"%Y-%m-%d").csv /home/vyv/data/AWS/ 2>&1 >> /home/vyv/data/AWS/scp-log.txt

This command simply takes the file that has the current date in its filename from a directory on a remote server and stores it to a directory on the local server and prints out the log file in the same directory.

Public key authentication is setup so there is no prompt for the password when run manually.

I have it configured in crontab to run 3 minutes after the top of every hour as in the following format -

3 * * * * scp usrname@storage-server:/share/Data/homes/AWS/2301KM-$(date +"%Y-%m-%d").csv /home/vyv/data/AWS/ 2>&1 >> /home/vyv/data/AWS/scp-log.txt

However, I wait patiently and don't see any files being downloaded automatically.

I've checked the /var/log/cron logs and see an entry on schedule like this -

Feb 9 17:30:01 intranet CROND[9380]: (wzw) CMD (scp usrname@storage-server:/share/Data/homes/AWS/2301KM-$(date +")

There are other similar jobs set in crontab that work perfectly.

Can anyone offer suggestions/clues on why this is not working?

Gratefully, Rakesh.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
  • 1
    Please take a look at [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting). – Cyrus Feb 13 '22 at 20:31
  • 1
    `%` is a special character in a cronjob. Escape it with a backslash. – Cyrus Feb 13 '22 at 20:33
  • Try making a bash file to run the job and run that fron Cron. That way you can test the script first. –  Feb 13 '22 at 21:17
  • `2>&1 >>somefile` doesn't do what you want; you need to put the `2>&1` *after* the `>>somefile`. See [this question](https://stackoverflow.com/questions/17975232/shell-redirection-i-o-order). – Gordon Davisson Feb 13 '22 at 21:25

1 Answers1

0

Use full path for scp (or any other binary) in crontab:

3 * * * * /usr/bin/scp usrname@storage-server:/share/Data/homes/AWS/2301KM-$(date +"%Y-%m-%d").csv /home/vyv/data/AWS/ 2>&1 >> /home/vyv/data/AWS/scp-log.txt