Linux Scripts.

This is where i will post little tidbits of information, little scraps of knowledge, mostly for my own use as an easy repository for myself. I will be putting useful linux scripts/sequence of commands in here that i’ve put together and figured out how to use. A lot of these will be dealing with converting video from the command line in linux.

Note. None of these contain any fancy things like “error checking” or anything like that. The goal here is to be able to more or less copy and paste the command and be able to use it.

Note2. Some of these commands don’t tend to appear in the standard ubuntu repositories. Medibuntu is an ubuntu repository containing things like decss that the ubuntu guys aren’t comfortable including in the main repositories. They have good instructions to set them up as an apt-get(aptitude) source but if you have any trouble/don’t use ubuntu, i can help.

Software used: (this will be updated as often as i add new scripts that use new software)

mplayer/mencoder (this is extremely useful) 
mkvtoolnix (set of tools for working with matroska files)
tar (used to create/extract tar bundles)
ssh (secure shell. secure remote access tool)
ogmtools (set of tools for working with ogm files)
geoip-bin (cli tools to lookup countries of origin for ip addresses)

 


Efficiently transfer a directory of files over ssh using tar.

tar cf - stuff | ssh bob@wendy.no.where.com tar xf - -C /home/brian

Scp is great but when you are transferring a large number of small files, things tend to slow down. This command uses tar to archive all the files into a single stream on the client which is then sent over the ssh connection and unarchived at the other end.
 


Rebuild the index of a .avi file.

mencoder -forceidx -oac copy -ovc copy a.avi -o b.avi

Where a.avi is the file to rebuild and b.avi is the outputed rebuilt file
 


Make a nicely formatted list of country of origin of ip address.

for i in `cat temp.txt`
do geoiplookup "$i" | awk '{print $4}' | tr '\n' ' '; echo "$i"
done

This is the same thing i use for my “I’m a real boy.” page. Make sure you paste the ip addresses, one per line, into a text file named temp.txt first. Also, try changing the $4 to $5, see if you like it better.
 


Convert all .ogm file in the pwd to .avi files.

for i in *.ogm
do mencoder "$i" -ovc copy -oac mp3lame -mc 0 -noskip -o output/"$i".avi
done

Strictly speaking, ogm files should not contain multiple audio tracks. However, many do. For those, add a -aid # to the command after mp3lame where # is the audio track counting from 0. By default, mencoder will grab only the first audio track. You can use the ogminfo command to list the audio tracks. Make sure you subtract 1 from the track you want though as mencoder starts counting them at 0.