LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-02-2010, 01:17 PM   #1
roystonlodge
Member
 
Registered: Jun 2008
Posts: 161

Rep: Reputation: 32
BASH Question: Using a loop to download a series of files


Never mind, I figured it out myself.

Firstly, the old version of BASH I'm using doesn't support
Code:
for i in {1..27}
So I had to use
Code:
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Secondly, it was simply
Code:
#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
do
  wget http://www.gutenberg.org/files/26290/mp3/26290-$i.mp3
done
Sorry 'bout the pointless thread. I couldn't find a way to delete the thread, since I'd solved my own problem.




Quote:
I want to download some audiobooks from Gutenberg.org.

Unfortunately, Gutenberg doesn't save their audiobooks as one mp3 file. The audiobook is broken up into a series of mp3 files.

I want to use wget and a BASH script to download an entire audiobook, but I don't know how to place the variable inside the URL.

Here's a pseudo-idea of what I'm trying to do (I know this is the incorrect syntax. I just want to give you the idea.):

Code:
#!/bin/bash
for i in {1..27}
do
  wget http://www.gutenberg.org/files/26290/mp3/26290-"$i".mp3
done


In other words, I want to set a loop that tells wget to download
http://www.gutenberg.org/files/26290/mp3/26290-1.mp3
http://www.gutenberg.org/files/26290/mp3/26290-2.mp3
http://www.gutenberg.org/files/26290/mp3/26290-3.mp3
http://www.gutenberg.org/files/26290/mp3/26290-4.mp3
etc, all the way to
http://www.gutenberg.org/files/26290/mp3/26290-27.mp3



Anybody have some advice for me on the correct syntax?

Last edited by roystonlodge; 02-02-2010 at 01:31 PM.
 
Old 02-02-2010, 02:13 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello roystonlodge,

you may as well use the "-r" option of wget to download all mp3-files recursively. Read the manpage of wget, there are some interesting informations. Be aware of the differences in how wget handles http and ftp.

Markus
 
Old 02-02-2010, 02:18 PM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Just for completeness you can also use:

Code:
for i in $(seq 1 27)
in case wget cannot do this.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through all files in a directory. Bash/Perl script? Nzo Linux - Newbie 9 12-09-2009 07:09 PM
Bash Script Loop Question SoulShaker Linux - Server 5 06-17-2009 01:44 PM
Bash script Question while loop glennph93 Programming 6 05-25-2007 03:27 PM
BASH 'while' loop question GSMD Programming 4 04-13-2007 12:51 AM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 AM.

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