Reputation: 1220
I know how to download all the samples from a SFTP server all at once and using the script mentioned below.
#download.sh
sshpass -p password sftp [email protected]:/Files/2017-05-05-00.zip ~/local_machine/2017-05-05/
sshpass -p password sftp [email protected]:/Files/2017-05-05-01.zip ~/local_machine/2017-05-05/
sshpass -p password sftp [email protected]:/Files/2017-05-05-02.zip ~/local_machine/2017-05-05/
.................................................................
sshpass -p password sftp [email protected]:/Files/2017-05-05-23.zip ~/local_machine/2017-05-05
Instead of running the script ( download.sh
) to download all the files at once , How can i download the files on hourly interval. For example , On the above script
The first line in download.sh
( download of 2017-05-05-00.zip) need to happen at 7AM
and this is only for the file look up 2017-05-05-00.zip and rest of the lines should not be looked up at.
Second line in download.sh ( download of 2017-05-05-01.zip) need to happen at 8AM
and So on till 23rd file.
When one is getting executed , None of the other files shouldn't be looked up.
Not sure how to do this using bash cron job , Any suggestions on how to do this please ?
Upvotes: 1
Views: 266
Reputation: 88756
Try this cronjob with GNU date:
0 * * * * sshpass -p password sftp [email protected]:/Files/$(date +"\%Y-\%m-\%d-\%H" -d "-7 hours").zip $HOME/local_machine/$(date +"\%Y-\%m-\%d" -d "-7 hours")/"
Usually it is necessary to escape %
with a \
in a cronjob.
Upvotes: 4