LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script Question while loop (https://www.linuxquestions.org/questions/programming-9/bash-script-question-while-loop-514730/)

glennph93 12-29-2006 06:15 PM

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

PTrenholme 12-29-2006 08:44 PM

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>

glennph93 12-29-2006 10:00 PM

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.

glennph93 12-30-2006 10:05 AM

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

gorbeia 02-15-2007 09:36 AM

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


glennph93 02-15-2007 11:51 AM

Thanks gorbeia, I haven't tried it yet but it makes sense to me that it will work.

Brotherred 05-25-2007 03:27 PM

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?


All times are GMT -5. The time now is 08:09 AM.