Jump to content

Recommended Posts

Posted

Im after a bash script that will do the following,

 

for every file in the current folder (which will be .avi or .mkv)

 

execute this command

 

mencoder input.file.name.avi -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=432:240,harddup -lavfopts format=psp -ofps 30000/1001 -o ouput.file.name.mp4

 

but replace the filenames from the files from the list - it doesnt even matter if the output then becomes output.file.avi.mp4

 

could someone knock something up for me please, Its pretty late and I want to let this run over-night and I dont really have time to teach myself the syntax (sorry if this seems lazy)

 

:)

Posted
Im after a bash script that will do the following,

 

for every file in the current folder (which will be .avi or .mkv)

 

execute this command

 

mencoder input.file.name.avi -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=432:240,harddup -lavfopts format=psp -ofps 30000/1001 -o ouput.file.name.mp4

 

but replace the filenames from the files from the list - it doesnt even matter if the output then becomes output.file.avi.mp4

 

could someone knock something up for me please, Its pretty late and I want to let this run over-night and I dont really have time to teach myself the syntax (sorry if this seems lazy)

 

:)

 

Is this a *nix question again or is this just a general vbs / java script type question ?

Posted (edited)

FILES="*.avi"

for f in $FILES; 
do 
mencoder $f -oac lavc -ovc lavc -of lavf /
 -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac /
-af lavcresample=48000 -vf scale=432:240,harddup -lavfopts /
format=psp -ofps 30000/1001 -o  $f.mp4
done

 

That, I think, would convert just the avi files. You could have the same block below, with FILES=*.mkv instead, but it can probably be done with a | perhaps. Can't test it as i'm in Windows at the moment *eugh* :p

 

Or something similar. Been a while since I did proper bash stuff... Should help you in the right direction though.

 

I'm sure Geoff will be along soon enough :p

Edited by localzuk
tidy
  • Thanks 1
Posted (edited)

You don't need a for loop, find will do it without bashims:

 

find . -type f -name "*.avi" -o -name "*.mkv" -exec mencoder "{}" -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=432:240,harddup -lavfopts format=psp -ofps 30000/1001 -o "{}.mp4" \;

Edited by powdarrmonkey
  • Thanks 3
Posted
You don't need a for loop, find will do it without bashims:

 

find . -type f -name "*.avi" -o -name "*.mkv" -exec mencoder "{}" -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=432:240,harddup -lavfopts format=psp -ofps 30000/1001 -o "{}.mp4" \;

 

This is why I love Bash. So versatile!

Posted (edited)

In Debian-land we have the check-bashisms tool (part of the package maintenance toolkit); portability is especially important right now because we're changing the default system shell to dash, which would have broken many many packages a couple of years ago. It's been a monumental effort.

 

Ubuntu have already been through this process.

Edited by powdarrmonkey
Posted (edited)
In Debian-land we have the check-bashisms tool (part of the package maintenance toolkit); portability is especially important right now because we're changing the default system shell to dash, which would have broken many many packages a couple of years ago. It's been a monumental effort.

 

Ubuntu have already been through this process.

 

Why is bash being replaced by dash, a cut down, less feature-filled version? One that misses some key POSIX requirements at that?

 

EDIT: It's down to 'speed' which is a bizarre reason considering how little time bash takes to start on anything moderately modern.

Edited by localzuk
Posted

It's lighter and faster, especially for embedded systems that don't have a lot of resources to spare - getting boot time down is our major aim. It's also easier to guarantee its presence on a base system because there are fewer dependencies. The few bits that are missing from POSIX are in developement AFAIK, but aren't common problems and so far (touch wood) we haven't had any disasters :)

 

Ubuntu have a nice wiki page with a list of common bashisms: https://wiki.ubuntu.com/DashAsBinSh. The user shells aren't changing, just system shells.

Posted

Can I just hijack this because I've been doing something a bit related to this and started with a loop and then realised that find did more or less what I want?

 

I've got a set of users whose Windows roaming profiles are stored on a Linux server. I'm trying to find those who haven't used the profile for (say) 90 days. Each profile has a folder called .pds

 

What I've got so far is:

 

for folder in `find . -type d -name '*.pds' -maxdepth 1`
do
 echo $folder
 du $folder -hc | grep total
 find $folder -name 'ntuser.dat'  -ls
done

 

This kind of works but it's messy - I get output looking like this:

./cbm.pds

1.4M total

472818 772 -rwxr--r-- 1 cbm stats 786432 Jul 17 2008 ./cbm.pds/ntuser.dat

 

I can live with the first two lines - it wouldn't be a big deal to process those but I'd really like to just get the date on the third line. I *think* I need to take the output of the second find command and pipe it through "cut" but I can't work out how to do that - the exec command looks promising but I can't make sense of how to use it.

 

Any offers?? Even if it's "start again, this is rubbish" :-)

Posted

@srochford: How's this?

 

find $folder -name 'ntuser.date' -ls | grep -o -E "[a-zA-Z]{3}(\s+)[0-9]+(\s+)[0-9]{4}"

 

A grep using regular expression for the date format.

Posted

just booting linux box at the mo, but AWK should do what you want.

 

try

 

find $folder -name 'ntuser.dat'  -ls | awk '{printf $8 ":" $9"\n"}'

 

also stat

 

stat -c %y ntuser.dat   | awk '{ printf $1 "\n"}'

  • Thanks 2
Posted
You don't need a for loop, find will do it without bashims:

 

find . -type f -name "*.avi" -o -name "*.mkv" -exec mencoder "{}" -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=432:240,harddup -lavfopts format=psp -ofps 30000/1001 -o "{}.mp4" \;

 

Thanks for that, but it doesnt seem to be working...

 


robert@rubuntu:/media/disk/woking$ ls
convert.sh                                          The.Shield.1x09.Throwaway.WS.XviDVD-TNS.avi      The.Shield.1x12.Two.Days.Of.Blood.WS.XviDVD-TNS.avi

robert@rubuntu:/media/disk/woking$ find . -type f -name "*.avi" -o -name "*.mkv" -exec mencoder "{}" -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=2500:acodec=libfaac -af lavcresample=48000 -vf scale=320:240,harddup -lavfopts format=psp -ofps 30000/1001 -o "{}.mp4" \;
robert@rubuntu:/media/disk/woking$

Posted
No need to fork anything:

 

find . -type f -name "ntuser.dat" -mtime +90

 

Thanks for that; it helps (need to replace the "." with $folder inside the loop so it starts at the right location and I've added -maxdepth 1 because the only ntuser.dat is going to be at the top level of the profile) but what I think I want (and it's a bit vague because this is a very messy project!) is to get a report of everything and then extract the old ones so they can be deleted/archived/whatever.

 

As it stands, this will give me a list that shows old ntuser.dat files and then no details when the file is newish and that will probably do.

 

I think the awk method is probably the right way to go to clean up the output - I'll keep playing :-)

Posted

Thanks - I've got almost what I wanted now by just bashing my head against the wall a few times :-)

 

for folder in `find . -type d -iname '*.pds' -maxdepth 1`
do
 find $folder -iname ntuser.dat -printf "%h %TY-%Tm-%Td\n"
 du $folder -hc | grep total | awk '{printf $1 "\n"}'
done

 

Just some notes for me to find later ...

 

first line finds all the directories matching "*.pds", only going down 1 level and sets up a loop to process them

 

next find statement searches from that folder using a case insensitive search for files called ntuser.dat When it finds them, it prints the name of the parent directory then the year, month and day on which the file was last modified

du shows the folder size(s) from $folder down; the grep command just finds the one which says "total" and the awk statement returns field 1 only (just loses the word "total" to make it a bit tidier)

 

I end up with output looking like this:

 

./spmoon.pds 2008-10-24

2.0M

./jstoppa.pds 2008-08-19

3.4M

 

which is probably good enough for now.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...