Simple curl based download manager

It resumes downloads and loops till the file is downloaded. On  the anvil-A conf file which can be parsed for list of urls.

It even shuts down after a predetermined interval.

#!/bin/bash
url="$1"
#export CURLOPT_CONNECTTIMEOUT=200000
#export CURLOPT_TIMEOUT=200000

#See if the last char in path is a slash. Else add it
#lchr=`expr substr $targetDIR ${#targetDIR} 1`
#lchr=${targetDIR#${targetDIR%?}}
minstoshutdown=120

sudo shutdown -h +$minstoshutdown &

sleeptime=10
syntax="\
Syntax:
cdown [URL]"

if [ "$url" = "" ]
then
echo "You need to url a file to upload!"
echo $syntax
exit 1
fi

coman="curl -C - -J -O $url"
echo "Command is :"
echo $coman

excode=1
text="Starting download...."
tries=0

while [ "$excode" -ne "0" ];
do
echo
let tries++
echo $text$tries
eval $coman

excode=$?

echo
echo "Exited with code - $excode"
echo
if [ "$excode" -eq "6" ]
then
echo "Your internet connection seems to be down!"
fi
echo "Waiting $sleeptime secs before trying again..."
sleep $sleeptime;
text="Restarting download...Attempt No: "
done

if [ "$excode" -eq "0" ]
then
echo "Completed upload after $tries tries"
else
echo "Tried $tries times. Upload was interrupted."
fi[/code]
 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.