1#! /bin/bash 2 3# get a list of urls and corresponding output file names, then parse them to wget 4 5LOGTAG="nameget.sh" 6args=("$@") 7list=${args[0]} 8 9if[[$list==""]] 10then 11printf"\n\x1b[31mWrong number of arguments\x1b[0m\n\n" 12printf"Usage: nameget LIST [DESTINATION] [ARGS]\nwhere LIST is a text file of format [url] [name] (one pair per line)\n[DESTINATION] is a path appended to the start of each [name] in LIST\n[ARGS] is passed directly to wget" 13exit1 14fi 15 16if[[-d${args[1]}]];then# check if args[2] is [DESTINATION] or [ARGS] 17 outdir=${args[1]} 18if[[ !$outdir=~ /$ ]];then# check if [DESTINATION] has a trailing / 19 outdir=$outdir/ 20fi 21shift2 22else 23shift1 24fi 25 26otherargs=$@ # set aside remaining arguments for passing to wget 27 28logger -s -t$LOGTAG"starting downloading files in$list" 29 30whileread -r url filename;do 31if wget --cut-dirs=100-np -e robots=off -O$outdir$filename $otherargs $url;then 32sed-i"/$filename/d"$list 33echo$filename 34 logger -s -t$LOGTAG"downloaded$filename" 35else 36 logger -s -t$LOGTAG"downloading of$filenamefrom$urlfailed." 37fi 38done<$list