Skip to content

Instantly share code, notes, and snippets.

@Tony3-sec
Created March 1, 2017 14:31
Show Gist options
  • Select an option

  • Save Tony3-sec/a49ce88689f44ec0bf06b0aacf989cd9 to your computer and use it in GitHub Desktop.

Select an option

Save Tony3-sec/a49ce88689f44ec0bf06b0aacf989cd9 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Script to bulk download the file from URL.
## If filename duplicates, append a counter to the filename.
if [ $# -ne 1 ]; then
echo "Usage: $0 [Needs file as arg]"
exit 1
fi
URL_list=$1
if [ ! -e $URL_list ]; then
echo "$URL_list does not exist."
exit 2
fi
count=0
echo "Fetching files....."
for url in $(cat $URL_list)
do
filename=$(basename "$url")
if [ -e $filename ]; then
count=$(($count + 1))
curl -s $url -o $filename$count
else
curl -s $url -O
fi
done
echo "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment