Wednesday, July 29, 2009

Rsync over SSH issues

I tried to rsync a DVD rip from laptop (OS X) to my desktop (Ubuntu) only to get a weird error telling me there was a 'corrupted MAC on input' almost instantly. The command I used was this:

rsync -av /path/to/movie me@mydesktop:/new/path/to/movie

I googled around for a bit and mostly found that people said this error was due to bad RAM. This didn't make sense to me though as rsync always worked just fine through my wireless connection. In this case, though, I went with ethernet since it would be much faster for transferring 4.5G. I also read that a bad nic would cause this, so I thought maybe my ethernet port was bad since I rarely use it. As it turns out, the problem went away as soon as I added the compression switch ( -z ) to rsync. Perhaps I was trying to pipe more data through than it could handle?

Tuesday, July 28, 2009

Progress viewer for local cp

As I mentioned I have been moving around large files and I thought it would be cool to have a progress bar for local copies in a Bash shell. After a bit of digging around, I found out about a program called pv, which stands for Pipe Viewer. Basically you can stick pv in between commands to see how much and how fast data is passing through. For a local cp, it's as simple as this:

pv /path/to/file > /path/to/copied/file

For a little more complexity, you can make a function out of it, and place it in ~/.bashrc to be sourced automatically:


progcp() {

if [ -d "$1" ]; then
echo "Input is a directory. Exiting."
return
fi

if [ -d "$2" ]; then
OUTFILE="$2/"`basename "$1"`
else
OUTFILE="$2"
fi

pv "$1" > "$OUTFILE"
}


I'm interested to know how to add normal command-line switches to a Bash function, so you could add flags like -r (recursive), or some of pv's switches, but this function works well for a single file local copy, such as a movie or an iso. Just call it like this:

progcp /path/to/file /path/to/output/file/or/directory

Finding duplicate filenames in a Bash shell

Several years ago, when DivX was the big thing, I ripped my DVD library to DivX/mp3 .avi's, but I've realized these are severely lacking as I can now crank up the bitrate with H.264/AAC .mp4's for high quality videos. Since disk space keeps getting cheaper and cheaper, I no longer even care how big the files get. Anyway, the point is, I've been ripping/encoding these movies as fast as possible into the same directory that all my other videos reside in, resulting in many duplicate files where one ends in .avi and the other ends in .mp4. I thought to myself that there must be a way to filter these out and after some fiddling I managed to produce a one-liner to do it. Here's what I came up with, but I'd love to know if anyone else has come up with a more efficient solution.

find . -type f -print0 | xargs -0 -I{} basename {} .avi | tr '\n' '\0' | xargs -0 -I{} basename {} .mp4 | sort | uniq -d

If the 'basename' command could take multiple arguments and remove multiple suffixes simultaneously, that would remove both 'xargs' command and the 'tr' command, but AFAIK it doesn't. Anybody know if it's possible to force xargs to do print0 like find does so I could eliminate the tr comman? Oh, and the sort isn't really necessary, but it was helpful as I was composing my pipes.

First Blog Post

Well, as the title says, this is my first blog post. I created it mostly to share random snippets of useful information regarding programming and Linux, though occasionally I might slip in some sports talk as I play Ultimate Frisbee and am an avid fan of football. Who knows how often I'll update this, but I hope the usefulness of the posts I create live on. Enjoy!