Register
It is currently Tue Sep 23, 2014 8:20 am

Script not working


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sun Feb 20, 2011 5:26 am   

Joined: Sun Feb 20, 2011 5:17 am
Posts: 3
Well at least a part of it... ;)

Code:
#!/bin/bash

OUTPUTDIR="mp3"

for FILE in *.flv; do

ffmpeg -i "$FILE" -acodec libmp3lame -ab 256k -ac 2 -ar 44100 $OUTPUTDIR/"${FILE%.flv}.mp3"

done

cd $OUTPUTDIR

find . -type f -iname '*.mp3' -print0 | xargs -0 mp3gain -r -k



This script is located in /usr/local/bin and converts the flv files in the current directory to mp3 files in a directory called mp3 that is in the current directory.

eg:
tmp/ - flv files go here
tmp/mp3 - script produced mp3 files go here...

Why doesn't the find command actually run?? The script stops dead as if the cd command does not work and obviously the find command doesn't find anything!

If I manually run the find command in the mp3 directory that works fine...

Total beginner here too! ;) Cant seem to fathom it out - If anyone has any good links to pdfs/docs for BASH Scripting I'm all ears!


Top
 Profile  
 PostPosted: Sun Feb 20, 2011 6:46 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
The script itself seems okay (apart from some if-then-else-fi's in case of errors)
The only tip I can give you if you want to debug the script yourself is: put a set -x before the commands you want to debug and set +x after the last command. If you want to debug the entire script, which might produce quite a lot of output, put it right below the #!/bin/bash line.


Top
 Profile  
 PostPosted: Sun Feb 20, 2011 9:39 am   

Joined: Sun Feb 20, 2011 5:17 am
Posts: 3
Patsie wrote:
The script itself seems okay (apart from some if-then-else-fi's in case of errors)
The only tip I can give you if you want to debug the script yourself is: put a set -x before the commands you want to debug and set +x after the last command. If you want to debug the entire script, which might produce quite a lot of output, put it right below the #!/bin/bash line.


Thanks like I said complete beginner to scripting so I need all the help I can get!


Top
 Profile  
 PostPosted: Mon Feb 21, 2011 11:21 pm   

Joined: Sun Feb 20, 2011 5:17 am
Posts: 3
Been doing some testing/debugging on my script...

if I put it in /usr/local/bin the last two lines won't work

if I put it in /home/martin/bin they will - So I think thats where I shall keep it...

Why is that anyone know..??


Top
 Profile  
 PostPosted: Tue Feb 22, 2011 1:07 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
Code:
#!/bin/bash

OUTPUTDIR="/PUT/FULL/PATH/HERE/mp3"

for FILE in *.flv; do

ffmpeg -i "$FILE" -acodec libmp3lame -ab 256k -ac 2 -ar 44100 $OUTPUTDIR/"${FILE%.flv}.mp3"

done

cd $OUTPUTDIR

find . -type f -iname '*.mp3' -print0 | xargs -0 mp3gain -r -k


The command works in whatever directory you call it in.

So calling the command "cd mp3" in the script might not be the best way to do that, as some directory might not contain a "mp3" dir. Putting the full path in the output variable would be the best way to go there.

Also, when running the command from /usr/local/bin or cron or other places than your own directory, or if your running it as another user, you could have $PATH issues, IE: commands might not be in your path.

echo $PATH

Many times, simply putting the full path to every command you call can fix those issues.

IE: /full/path/to/ffmpeg instead of just ffmpeg.

Clear as mudd right ? ;)


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP