LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 07-05-2004, 03:59 AM   #1
seabass55
Member
 
Registered: Jan 2003
Location: 127.0.0.1
Distribution: Fedora&Gentoo
Posts: 207

Rep: Reputation: 30
Script to run script in multiple directories...


okay...using mpgogg to convert my mp3's to ogg's.

All my mp3's were previously arranged in directories as follows...

rootmusicdir>Artist>Album>Songs

So I wrote a script to run mpgogg with the options I want and called it moog (only way I can do it now is using mc to switch directories and typing moog in the command line)

Here's what I've been trying with...

find /home/seabass55/music/ -iname *.mp3 -exec /sbin/moog \;

/music/ is the root music directory...I've fiddled with different combinations of the above adding -depth -mindepth, -maxdepth and a bunch of other things and I just can't get it to work :-(

Thanks folks
Seabass
 
Old 07-05-2004, 04:21 AM   #2
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 57
How does your script expect to be called? Something like moog filename.mp3? If that's the case the only thing you should need to add to your find line is curly braces, which in find expands to the full filename: find /home/seabass55/music/ -name *.mp3 -exec /sbin/moog {} \;


Håkan
 
Old 07-05-2004, 04:59 AM   #3
seabass55
Member
 
Registered: Jan 2003
Location: 127.0.0.1
Distribution: Fedora&Gentoo
Posts: 207

Original Poster
Rep: Reputation: 30
Actually the command just needs to run in that directory....it can run on the file but if it has spaces which some do it needs to be in quotes so it's easier to just run it in the directory itself...it'll do all the files in that directory.
 
Old 07-05-2004, 08:43 AM   #4
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
moog_it() {
for file in $1/* ; do
/sbin/moog "$file"
done
}
recurse() {
for $this_dir in $1/* ; do
if [ -d "$this_dir" ]; then
moog_it "$this_dir"
recurse "$this_dir"
fi
moog_it $1
}


run it with "recurse /path/to/directory"
I'm not positive this will work....it's a modification of a different script

Last edited by mikshaw; 07-05-2004 at 08:53 AM.
 
Old 07-05-2004, 09:10 AM   #5
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 57
If you only want a list of directories which contain mp3's (through which you want to iterate and run your script) you could try something like this:
Code:
for dirname in `find . -name *.mp3 -exec dirname {} \; | sort -u` ; do cd "$dirname"; /sbin/moog; done
This does have the problem with dirnames with spaces and I can't remember the neat way of solving that right now.


Håkan
 
Old 07-06-2004, 12:44 AM   #6
seabass55
Member
 
Registered: Jan 2003
Location: 127.0.0.1
Distribution: Fedora&Gentoo
Posts: 207

Original Poster
Rep: Reputation: 30
I still had problems with it. So I decided to just dump the spaces (got a perl script for that) and ran the origional command.

Thanks for the help all.

seabass
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 06:49 AM
run script on multiple files statmobile Programming 6 07-16-2004 11:35 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
can't run a script script from icon in konqueror scottsteibel Linux - Software 1 08-02-2003 07:59 PM


All times are GMT -5. The time now is 11:02 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