help to make script run recursively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to make script run recursively
# 1  
Old 05-01-2012
help to make script run recursively

I have this little bash script I use to transcode mkv files using handbrake.
Code:
#!/bin/bash

sourcedir="/media/raid10/video/to_be_encoded_series"
destdir="/media/raid10/video/series"
cd "$sourcedir"
for i in *.mkv; do

HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mkv" -e x264 -q 20.0 -E copy -B auto -6 auto -R Auto -D 0.0 -f mkv --detelecine --decomb --loose-anamorphic -m -x b-adapt=2:rc-lookahead=50

mv "$i" /media/raid1/orig_series_mkv/"$i"
done

This is great for transcoding a batch of films all contained in the source directory, but I can't make it run recursively for files grouped into sub directories. I would also like to preserve the directory structure in the destination directory.

Thanks

Last edited by joeyg; 05-02-2012 at 12:18 PM.. Reason: typo
# 2  
Old 05-01-2012
Use find to search the subdirs and feed its output to a loop...
Code:
find <path_to_dir> -type f -name "*.mkv" | while read i
do
     <HandBrakeCLI command and args.>
     <mv command and args.>
done

# 3  
Old 05-01-2012
Thanks,

Will this also preserve the directory structure in the destiation directory?

ie
/source/TVseries/original_file.mkv
to
/destination/TVseries/transcoded_file.mkv
# 4  
Old 05-02-2012
Quote:
Originally Posted by barrydocks
Thanks,

Will this also preserve the directory structure in the destiation directory?

ie
/source/TVseries/original_file.mkv
to
/destination/TVseries/transcoded_file.mkv
Yes it will...as long as you use the move comand in your first post.
# 5  
Old 05-03-2012
No luck I'm afraid, Handbrake runs but doesn't transcode anything and then there is an error with the mv command. I have commented out the cd and mv command to just leave the handbrake args but still no luck, here is my script:
Code:
#!/bin/bash

sourcedir="/media/raid10/video/to_be_encoded_series"
destdir="/media/raid10/video/series"
#cd "$sourcedir"

#for i in *.mkv; do
find "$sourcedir" -type f -name "*.mkv" | while read i
do

HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mkv" -e x264 -q 20.0 -E copy -B auto -6 auto -R Auto -D 0.0 -f mkv --detelecine --decomb --loose-anamorphic -m -x b-adapt=2:rc-lookahead=50

#mv "$i" /media/raid1/orig_series_mkv/"$i"
done

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Trying to make a script to run 3 other scripts in a screen.

Hello, my name is Spurkle. I'm new to linux stuff. Currently I am trying to make a script which will run three other scripts in screen. This is the code: sudo screen -S hubServ /var/servers/hub/hub.sh sudo screen -S facServh /var/servers/factions/factions.sh sudo screen -S bunServ... (5 Replies)
Discussion started by: Spurkle
5 Replies

2. Shell Programming and Scripting

How to make a bash or shell script run as daemon?

Say i have a simple example: root@server # cat /root/scripts/test.sh while sleep 5 do echo "how are u mate" >> /root/scripts/test.log done root@server # Instead of using rc.local to start or another script to check status, I would like make it as daemon, where i can do the following: ... (2 Replies)
Discussion started by: timmywong
2 Replies

3. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

4. Shell Programming and Scripting

how we can make shell script not to run

Hi,shell script is scheduled from maestro and we want mastero should not run shell script so can we edit the shell script so that it should run.ThanksPrakash (5 Replies)
Discussion started by: prakashdba2010
5 Replies

5. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

6. Shell Programming and Scripting

Need help howto make a script for Set SNOOP run for 5 minutes

Hi all, I want to monitoring my interface every 6 hours where i want to run snoop command to capture all packet through the interface, so i want running snoop then snoop will run for 5 minutes after that snoop stop then will start again after 6 hours than run for 5 minutes again. thereis any... (9 Replies)
Discussion started by: tindasz
9 Replies

7. Shell Programming and Scripting

How to make a script to run everytime a new file is copied into a directory??

Hi folks I have a unix script script1 in a directory folder1 and also I have few input log files in this directory. My input log files will be copied into this directory folder1 from the portable thumb drive. Now what I want is I need to run this script1 whenever any new file is copied... (2 Replies)
Discussion started by: ks_reddy
2 Replies

8. UNIX for Dummies Questions & Answers

help to make list of files and run script..

Hey, I have finally made a command that works and now has to run it on 200+ files to run it on. How do I do that? Just fyi and if it complicates anything my commandline is: awk '{if ($1 ~ /1/) print $2}' file (yup, is should print $2 if $1 is a certain value) It doesn't work when I: ... (2 Replies)
Discussion started by: lost
2 Replies

9. Shell Programming and Scripting

Can anyone make this script run faster?

One of our servers runs Solaris 8 and does not have "ls -lh" as a valid command. I wrote the following script to make the ls output easier to read and emulate "ls -lh" functionality. The script works, but it is slow when executed on a directory that contains a large number of files. Can anyone make... (10 Replies)
Discussion started by: shew01
10 Replies
Login or Register to Ask a Question