Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't download an existing file with axel

I have an script that reads some urls and get them to axel to download them. I want stop script on sometimes and resume it further. Axel can resumes file downloading. So if I press Ctrl+C when downloading, the next time, it starts from the resume of file.

but axel doesn't check that the file existed. So it appends ".0" to the end of file name and start downloding it twice. How I can tell to axel if the file with same name existed, skip that and don't downloading it??

like image 402
Babak Mehrabi Avatar asked Nov 04 '12 10:11

Babak Mehrabi


2 Answers

If you want to make sure axel will resume, as it does per file name and not per url, you should use a deterministic name for the file:

axel -o NAME_OF_EXISTING_FILE

If you want to check if file exists

if [ -f $FILE ]; then
   echo "File $FILE exists."
    # operation related to when file exists, aka skip download
else
   echo "File $FILE does not exist." 
   # operation related to when file does not exists
fi

In case of axel, you want to start download if
1. you do not have that file localy, or
2. you have a partial download, so:

function custom_axel() {
    local file_thingy="$1"
    local url="$2"
    if [ ! -e "$file_thingy" ]; then
        echo "file not found, downloading: $file_thingy"
        axel -avn8 "$url" -o "$file_thingy"
    elif [ -e "${file_thingy}.st" ]; then
        echo "found partial downloaf, resuming: $file_thingy"
        axel -avn8  "$url" -o "$file_thingy"
    else
        echo "alteady have the file, skipped: $file_thingy"
    fi
}

This could go into ~/.bashrc or into /usr/bin/custom_axel.sh and later:

while read URL; do
    name=$(basename "$URL") # but make sure it's valid.
    custom_axel "$name" "$URL"
done < /my/list/of/files.txt
like image 84
hkoosha Avatar answered Sep 21 '22 07:09

hkoosha


Axel use a state file, named with a .st extension.
It is regularly updated during download.
When axel is started, it first checks for <file> and <file.st>. If found, download is resumed where it stopped.
Which version do you have ? I got Axel version 2.4 (Linux) and it resume correctly after a CTRL+C.

like image 38
Setop Avatar answered Sep 24 '22 07:09

Setop