Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wget Script
#1
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.


Code:
#!/bin/bash
#Read Password
echo -n Password:
read -s password
echo
#Run Command
wget -i TextInputFile --no-check-certificate --user email@email.com --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.

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

Code:
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."
@ludditegeek
Rick's Tech Stuff
GitHub
Reply
#3
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.
Reply
#4
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
Code:
-O newname1 URL1
-O newname2 URL2
-O newname3 URL3
...

The script could look like
Code:
#!/bin/bash
read -p "Password: " -s password
echo
while read -r FILE; do
   wget  --no-check-certificate --user email@email.com --password $password $FILE
done < TextInputFile

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

Example login:

Code:
curl --user user:pass https://www.site.tld/page/

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

Code:
curl -o newfilename.zip --user user:pass https://www.site.tld/page/originalfilename.zip

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

Code:
curl -k -o newfilename.zip --user user:pass https://www.site.tld/page/originalfilename.zip
Jeremy (Mr. Server)

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


Forum Jump:


Users browsing this thread: 1 Guest(s)