Specific example here is that I want to insert a string inside a second (last) instance of another string, while ignoring another string, e.g. for the input example below, I want to replace every last instance of group_ or field_ on each line, but skip any that contain _type.

The problem is negation is accomplished with:

sed '/pattern to ignore/!/s/pattern to replace/replace with/'

This works fine with single quotes, but need double quotes to use shell variables inside sed. With double quotes, the shell complains about the exclamation mark:

Read the rest of this entry…

Here’s a super simple shell script to check for APC cache fragmentation and send an alert email root. Depends on apc_info.php from http://code.google.com/p/munin-php-apc/.

Read the rest of this entry…

Bash can only compare integers (e.g. 0, 1, 2, etc), not floating point numbers (e.g. 0.0, 1.3, 2.99, etc). Searching the web produced all sorts of solutions that involved either too much code or required other programs like “bc”. Most servers won’t have “bc” installed, so I came up with the following simple solution that seems to work.

My use case is to check if a value is greater than zero, unfortunately the Bash built in “-gt” won’t work because “0″ in this situation can be reported as “0.00″. My solution is to simply check for presence of an integer greater than 0, regardless of location:

Read the rest of this entry…

I frequently need to rename files by moving a string that’s part of the existing file’s name to the beginning of the filename. Here’s a script that will take a string as an argument and rename files by moving the string to the start of the file name.

Read the rest of this entry…

Picked up an inexpensive camcorder, Samsung HMX-H300, for $260 at BHPhoto, to replace my ancient Canon Optura 300, which we’ve been using to film our wakeboarding for training purposes. No more time consuming dv transfer and compression since the HMX-H300 saves footage as H.264 encoded files. It’s also much better quality. Not the best, though, as according to reviews, several other consumer grade camcorders produce better looking video (for a couple hundred bucks more). The HMX-H300 also doesn’t support lens accessories like filters and telephoto/wideangle adapters and has a terribly narrow field of view. However, it does offer an unusually good optical zoom for its class (30x).

For shooting wakeboarding, which essentially comes down to filming well lit subjects 50-80 ft away, outdoors, it should be just fine. I’m also pleased that it can do 720p60, while some of its more highly reviewed competitors capture only interlaced at 30 fps. The HMX-H300 can do 1080i, 720p and 480p at 60fps. I wanted a minimum of 60 fps since that can be played back at 24 fps for lossless 2.5x slow motion.

There are several tools that allow overriding the frame rate of a 60 fps video to 24 fps to achieve 2.5x slow motion playback. The following example uses mencoder. The command as listed will also drop audio, since I don’t want it for my application.

Read the rest of this entry…

I’m running Debian Wheezy (testing) and noticed that Preferences and Administration launchers have gone missing from my System menu. After some digging, the reason appears to be that Gnome 3 has been released and its packages have been making their way into my system. Perhaps because I update with “aptitude safe-upgrade” instead of “full-upgrade”, Gnome 2 hasn’t been replaced with Gnome 3 entirely. So far the missing menu items have been the only symptom I’ve noticed.

Anyway, my fix is more of a workaround and it consists of simply creating a custom application launcher for the Gnome Control Center which seems to provide access to all the admin tools previously accessible via the Preferences and Administration menus.

To create a launcher:

Read the rest of this entry…

Let’s say you’re using jigdo to download installation images of your favorite operating system. If you don’t, you should, because jigdo allows you to quickly and efficiently update your ISO images by downloading only the differences between your existing ISO and the latest currently available, saving time and bandwidth. Here’s how to get started with jigdo.

If you’ve got a directory full of .iso files and matching .jigdo files, instead of updating each individually, could run the script below whilst inside the directory to update them all at once.

Script in action:

Read the rest of this entry…

I’ve got a crappy old dv camcorder that we’ve been using to film our wakeboarding. The video quality is crap by modern standards, but good enough as a training tool.

There are a ton of video capture and processing tools packaged for Debian and easily installed with apt-get. After trying a few, I’ve found dvgrab and ffmpeg to work well with minimal effort on my part.

Read the rest of this entry…

Hot on the heels of the shell script to refresh a predefined set of regularly changing pages in varnish cache, comes the updated version of single page refresh script. The previous version didn’t automatically refresh the cache with curl after purging.

Script in action:

ak@loon:~$ v-purge /alain/
Purging old version from cache:
-------------------------------
0x2e112400 1321656227.056981     0 	req.url ~ ^/alain/$
 
Populating cache with new page content:
---------------------------------------
200 http://giantdorks.org/alain/

Download the script:

Read the rest of this entry…

I have the varnish cache TTL set for a very long time (500 days), so cached content practially never expires. Every time I update this blog, there are several pages I need to purge. The following script seems to do a good job purging a list of pages and then immediately re-populating the cache with an updated version, so the next time a real visitor comes, there’s no waiting around for the slow backend to generate it, instead the amazing varnish promptly serves a hot copy from its cache.

Script in action:

1
ak@loon:~$ v-purge-common
-----------------------------
Purging old pages from cache
-----------------------------
0x2e105f00 1321650069.214849     0 	req.url ~ ^/$
0x2e111740 1321650069.354750     0 	req.url ~ ^/alain/$
0x2e118140 1321650069.498892     0 	req.url ~ ^/alain/feed/$
0x2e1183c0 1321650069.642832     0 	req.url ~ ^/alain/feed/atom/$
---------------------------------------
Populating cache with new page content
---------------------------------------
200 http://giantdorks.org/
200 http://giantdorks.org/alain/
200 http://giantdorks.org/alain/feed/
200 http://giantdorks.org/alain/feed/atom/

Download the script:

Read the rest of this entry…