From: Andrew Lorimer Date: Wed, 4 Jul 2018 11:34:02 +0000 (+1000) Subject: added nameget.sh X-Git-Url: https://git.lorimer.id.au/scripts.git/diff_plain/fbe27cd89c34b4a0834ca654e736afe09fa31b88?ds=inline;hp=fba9ea1185993be8eb674e59e75f8cceec7881bd added nameget.sh --- diff --git a/nameget.sh b/nameget.sh new file mode 100755 index 0000000..e8fbbfa --- /dev/null +++ b/nameget.sh @@ -0,0 +1,29 @@ +#! /bin/bash + +# get a list of urls and corresponding output file names, then parse them to wget + +args=("$@") +list=${args[0]} + +if [[ $list == "" ]] + then + printf "\n\x1b[31mWrong number of arguments\x1b[0m\n\n" + printf "Usage: nameget LIST [DESTINATION] [ARGS]\n where 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" + exit 1 +fi + +if [[ -d ${args[1]} ]]; then # check if args[2] is [DESTINATION] or [ARGS] + outdir=${args[1]} + if [[ ! $outdir =~ /$ ]]; then # check if [DESTINATION] has a trailing / + outdir=$outdir/ + fi + shift 2 +else + shift 1 +fi + +otherargs=$@ # set aside remaining arguments for passing to wget + +while read -r url filename tail; do + wget --cut-dirs=100 -r -np -nc --accept -e robots=off -O "$outdir$filename" "$url" $otherargs +done < $list