Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wget Script
Hi Folks,

So I'm trying to write a script that will grab multiple files from a website, save them locally, and rename them. The input file for all the URLs is from a .txt document. Everything works but I'd like to rename the files to something else.

#Read Password
echo -n Password:
read -s password
#Run Command
wget -i TextInputFile --no-check-certificate --user --password $password

Any ideas how I can have the files renamed upon download? Right now the files are named the same as the URL provided in the input text file.

wget with the -O option wiil save the file with whatever name you choose. (That's a capital O, not a zero)

wget -O filename
# or
wget --output-document=filename
 I don't know how that will work with the -i option and downloading multiple files. I've only used this option for downloading individual files.
The man page gives warnings about using the -N, -k, -r, and -p options but doesn't mention how it interacts with the -i option. It may be that the options after the -i act on each URL as if they were separate wget commands. You'll probably have to experiment with that. If that doesn't work, you may have to resort to a while loop to rename the downloaded files.
I hope I've been able to shed a little bit of light on your problem.
Rick Romig
"It's never wrong to introduce a child to Linux."
Rick's Tech Stuff
Thanks rickromig! Unfortunately I've already tried the -O option but can't seem to get it to change the names of multiple files without hard coding each of the links into the script. I thought about trying to embed the -O option in the text file but that doesn't work since it's just an input file and doesn't pass BASH commands. Hope this makes sense.
Your idea with the -O option inside the text file will work as intended, if you change your script accordingly.

The text file should contain something like
-O newname1 URL1
-O newname2 URL2
-O newname3 URL3

The script could look like
read -p "Password: " -s password
while read -r FILE; do
   wget  --no-check-certificate --user --password $password $FILE
done < TextInputFile

Just a thought. HTH
I would suggest you look into Curl.  It has better security and such.

Example login:

curl --user user:pass

To output to a file one uses the -o (letter o small if you want to rename the file locally)

curl -o --user user:pass

I should add you mentioned insecure (allow unverified SSL certs like self signed).  This is done with -k (lower k)

curl -k -o --user user:pass
Jeremy (Mr. Server)

* Desktop: Ubuntu MATE
* Windows are for your walls, Apple is for your health, Linux is for your computer

Forum Jump:

Users browsing this thread: 1 Guest(s)