From fbe27cd89c34b4a0834ca654e736afe09fa31b88 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Wed, 4 Jul 2018 21:34:02 +1000 Subject: [PATCH 1/1] added nameget.sh --- nameget.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 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 -- 2.47.0