LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-10-2011, 01:37 AM   #1
humlhr
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Rep: Reputation: 0
Need Help with bash scripting


i have number of urls that i wan to download. i download them with wget but i wan that wge download them and save them like files as part1 part2 part3.
where 1 2 3 are veriables that change with every next url.

plz help me
 
Old 12-10-2011, 02:05 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
wget has a -O option (O uppercase) to set the name of the downloaded file. If you have a list of URL stored somewhere you can easily loop over them using a while read construct and update the file count at each cycle. What have you tried so far?
 
Old 12-10-2011, 02:28 AM   #3
humlhr
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Original Poster
Rep: Reputation: 0
thanks for ur replay

i am not good in scriptings.

i have a sript
-------------------------
cd /media/All\ Madia/

for urls in `cat $1`
do

/usr/bin/wget -c --load-cookies /cookies.txt $urls

done
-------------------------

now i whant that when it download a file it rename it with a variable number
------------------
cd /media/All\ Madia/


for urls in `cat $1`
do


/usr/bin/wget -O file.$i.wmv -c --load-cookies /cookies.txt $urls

done
--------------
where i is a veriable like 1 2 3 4 5

plz modify this script
 
Old 12-10-2011, 04:30 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Almost there! There should be no problem using a for loop over the output of the cat command in this case (if I'm not wrong, the URLs cannot contain blank spaces) but in general I prefer the while read construct to correctly manage blank spaces, if any:
Code:
#!/bin/bash
i=1
while read url
do
  /usr/bin/wget -O file.$i.wmv -c --load-cookies /cookies.txt "$url"
  ((i++))
done < $1
In bash you can use the arithmetic operator to increment the i counter. The syntax i++ is inherited from the C language and means increment the current value of the variable by one. There is a similar ++i (with the plus signs before the variable name, but I spare you the details right now).

In addition, if you want to pad the number with zeros (useful if you have more than 9 files and you want to see them sorted correctly in a list) you can try the printf statement as in
Code:
/usr/bin/wget -O file.$(printf "%02d" $i).wmv -c --load-cookies /cookies.txt "$url"
Hope this helps.

Last edited by colucix; 12-10-2011 at 08:17 AM. Reason: English syntax
 
Old 12-10-2011, 08:38 AM   #5
humlhr
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Thank for your help.
its work for me.
again thanks
 
Old 12-10-2011, 08:44 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
Old 12-10-2011, 08:57 AM   #7
humlhr
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Original Poster
Rep: Reputation: 0
ok one more question. can i download files with axle but it did not sport cookies
 
Old 12-10-2011, 09:28 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Do you mean axel, the command-line download manager? I'm not experienced in using it, but googlin' around it looks like someone wrote a patch to read/load cookies from the firefox file cookies.sqlite. Here is the link. Hope this helps.

Edit: it might be useful to import your cookies.txt file into firefox. For this purpose there is a suitable add-on: Cookie Importer.

Last edited by colucix; 12-10-2011 at 09:34 AM. Reason: Added information
 
Old 12-14-2011, 09:55 AM   #9
humlhr
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Original Poster
Rep: Reputation: 0
thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
need help on bash scripting stympman Linux - Newbie 3 10-20-2008 06:20 PM
Bash scripting help arturhawkwing Linux - General 1 08-10-2006 11:54 AM
Bash scripting vinoth.ilango Solaris / OpenSolaris 6 10-29-2004 04:41 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration