LinuxQuestions.org
Help answer threads with 0 replies.
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 12-29-2006, 06:15 PM   #1
glennph93
LQ Newbie
 
Registered: Oct 2003
Location: pittsburgh
Distribution: Slackware 10.2,ubuntu
Posts: 10

Rep: Reputation: 0
Bash script Question while loop


Hi all

This is probably an easy question, but for some reason I can't figure out why my loop ends doing only one task.

Code:
#!/bin/bash
#used to create playable podcast files on my sony mp3 player
#jk 12-29-06


# datadir is the directory where you want altered podcasts saved to:
datadir=48k

# create datadir if necessary:
mkdir -p $datadir

while read podcast
	do
		podcast48k=48k$podcast
		/usr/bin/ffmpeg -i $podcast -ab 48 -ac 2 -ar 44100 -acodec mp3 $datadir/$podcast48k &> /dev/null
	done< podcast.m3u

####wrote the below to test what i think should happen and it does what i think####
#while read podcast
#	do
#		podcast48k=48k$podcast
#		echo $podcast
#		echo $podcast48k
#		sleep 2
#	done< podcast.m3u

exit

I'm using bashpodder to get my podcast, which creates a simple playlist named podcast.m3u. Then I need to convert the files into something my sony mp3 player can read(mainly 44100 sample rate). I'm going to run the above to do that, but it ends after 1 line of the .m3u file. Any help would be appreciated

Thanks John

Last edited by glennph93; 12-29-2006 at 10:11 PM.
 
Old 12-29-2006, 08:44 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You seem to be throwing away all messages from ffmpeg. Try it without the &>/dev/null to see if you might be getting an error return that's aborting your loop.

It's always a "good thing" to check after running a command to see if it has returned an error code.

<aside>
What's the point of defining datadir if you hard-code 48k in your output specification?
</aside>
 
Old 12-29-2006, 10:00 PM   #3
glennph93
LQ Newbie
 
Registered: Oct 2003
Location: pittsburgh
Distribution: Slackware 10.2,ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for responding,

I tried to do it with out &>/dev/null prior to adding it same result(i thought before the output was the problem so I added &>/dev/null).

I guess I could take datadir(!!oops i get it i corrected the code) out but I wasn't sure it would create it just by my hardcode.

Last edited by glennph93; 12-29-2006 at 10:12 PM.
 
Old 12-30-2006, 10:05 AM   #4
glennph93
LQ Newbie
 
Registered: Oct 2003
Location: pittsburgh
Distribution: Slackware 10.2,ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Well I solved my problem by going this route.

Code:
for podcast in `cat podcast.m3u`

	do
		podcast48k=48k$podcast
		/usr/bin/ffmpeg -i $podcast -ab 48 -ac 2 -ar 44100 -acodec mp3 $datadir/$podcast48k &> /dev/null
	done
not really satisfied, but it works.

Thanks John
 
Old 02-15-2007, 09:36 AM   #5
gorbeia
LQ Newbie
 
Registered: Feb 2007
Location: Basque Country
Distribution: Kubuntu and Debian
Posts: 1

Rep: Reputation: 0
The problem here is that ffmpeg is reading the standard input. This shold solve the problem:

Code:
while read podcast
do
  podcast48k=48k$podcast
  /usr/bin/ffmpeg -i $podcast -ab 48 -ac 2 -ar 44100 -acodec mp3 $datadir/$podcast48k < /dev/null
done< podcast.m3u
 
Old 02-15-2007, 11:51 AM   #6
glennph93
LQ Newbie
 
Registered: Oct 2003
Location: pittsburgh
Distribution: Slackware 10.2,ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks gorbeia, I haven't tried it yet but it makes sense to me that it will work.
 
Old 05-25-2007, 03:27 PM   #7
Brotherred
Member
 
Registered: Mar 2007
Location: Michigan
Distribution: Mandriva 2010.1
Posts: 37

Rep: Reputation: 15
Hello I run pcLos and I want to run a bash script to download my poddcasts regardless of what ever user is logged in. I am most likely to use Kpodder but who knows? Would I use cron? How do I do it?

Last edited by Brotherred; 05-25-2007 at 03:30 PM.
 
  


Reply

Tags
bash, pclinuxos


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM
while loop ending prematurely in a bash script meat-head Programming 7 05-08-2004 01:46 AM


All times are GMT -5. The time now is 03:36 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration