[Solved] Bash script to download data from url


You have two bits here. One is to schedule a cron job and the other is to get the file & save it.

Steps :

  1. Open the terminal & run crontab -e

    minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command

  2. In place of minute, hour, day, month & weekday. Also provide the command to run.

  3. The command to put up here is : wget www.manishshukla.com/files/"$(date '+\%d-\%m-\%Y')".csv

  4. Save the file & the jobs are scheduled.

In your case :

0 0 * * * wget --quiet -O www.manishshukla.com/files/"$(date '+\%d-\%m-\%Y')".csv

OR

0 0 * * * /usr/bin/curl www.manishshukla.com/files/"$(date '+\%d-\%m-\%Y')".csv

This would run the command every day at 0hrs 0mins.

Added \ to escape %, as it may not work in corntab without escaping.

Percent-signs (%) in the command, unless escaped with backslash (),
will be changed into newline characters, and all data after the first
% will be sent to the command as standard input.

4

solved Bash script to download data from url