A combination of an Upstart job and a cron job:
First, create an Upstart job. Create a file called ~/.config/upstart/my-download.conf
containing:
description "My download job."
start on resume-download
stop on stop-download
respawn
respawn limit 10 5
script
cd /path/to/download/folder
wget --continue uri://link/to/download
end script
Now, add a cron job to start and stop this Upstart job. Run EDITOR=gedit crontab -e
and add to the file:
0 0 * * * /sbin/initctl emit resume-download
0 5 * * * /sbin/initctl emit stop-download
You can manually start the download any time you want using:
initctl emit resume-download
# or
start my-download
And stop it any time using:
initctl emit stop-download
# or
stop my-download
- Due to the
respawn
in the job, Upstart will try to restart wget
if it exits. This can be useful if it timed out and exited at two in the morning. A limit is placed so that we don't have Upstart trying to start wget infinitely (e.g., the network is facing extended problems, the download was completed, etc.).
- We added
initctl emit
commands in the cron job. This way, if we create more such Upstart jobs, all of them starting on this event, this single cron entry will be enough to start all of them.