Commands.page Logo

Automate Daily Downloads Using aria2c and Cron on Ubuntu

This guide explains how to schedule automatic file downloads on Ubuntu systems. By combining the lightweight downloader aria2c with the cron job scheduler, you can ensure files are retrieved at specific times without manual intervention. The following steps cover installation, script creation, and cron configuration to streamline your download workflow.

Install aria2

Open your terminal and update your package list before installing the tool. Run the following command to install aria2 on your Ubuntu machine:

sudo apt update
sudo apt install aria2

Create a Download Script

You need a shell script to hold the download commands. Create a new file in your home directory named daily-download.sh using a text editor like nano:

nano ~/daily-download.sh

Inside the file, add the aria2c command with the URL of the file you wish to download. Specify the output directory using the -d flag. Your script should look similar to this:

#!/bin/bash
aria2c -d ~/Downloads https://example.com/file.zip

Save the file and exit the editor. Next, make the script executable by running:

chmod +x ~/daily-download.sh

Configure the Cron Job

Open the cron table for your user to schedule the task:

crontab -e

If prompted, select your preferred text editor. Add a new line at the bottom of the file to define the schedule. The following example runs the script every day at 2:00 AM:

0 2 * * * /home/your-username/daily-download.sh

Replace your-username with your actual Ubuntu username. Save and close the file. Cron will automatically install the new job.

Verify the Automation

To ensure the cron job is active, list your current cron tasks:

crontab -l

You can also check the system logs to verify execution after the scheduled time passes. View the syslog using:

grep CRON /var/log/syslog

Your files will now download automatically to the specified directory at the scheduled time each day.