Commands.page Logo

Use aria2c to Download File and Execute Script on Ubuntu

This guide explains how to automate tasks in Ubuntu using the aria2c command-line utility. You will learn how to configure aria2c to download specific files and automatically trigger a custom script once the download finishes. This process is useful for backups, media processing, or deployment workflows without manual intervention.

Install aria2

Open your terminal and install the package using apt:

sudo apt update
sudo apt install aria2

Create the Completion Script

Create a bash script that will run after the download. For example, create a file named process.sh:

nano process.sh

Add your desired commands inside the file. aria2c passes the file path as an argument to this script.

#!/bin/bash
echo "Download complete: $1"
# Add your processing commands here

Save and exit the editor.

Make the Script Executable

You must grant execute permissions to the script for aria2c to run it:

chmod +x process.sh

Run aria2c with the Callback

Use the --on-download-complete flag to specify the script path. Replace the URL with your target file:

aria2c --on-download-complete=./process.sh https://example.com/file.zip

When the download finishes, aria2c will execute process.sh and pass the downloaded file’s path as the first argument. You can verify this by checking the terminal output or the actions defined in your script.