Wildcard string matching on linux

If you’re on linux, the GNU C library has a handy function for doing wildcard matching called fnmatch. I notice it’s also supported in Python, PHP and Perl and probably in a few other scripting languages.

I’m amazed that I haven’t ever needed to do this before but I had the case this year that I needed to allow a list of strings to contain wildcards. At first I just implemented this myself as I only needed to support the wildcard on the ends of strings but once I started using it, I wanted to allow matching the wildcard in the middle of strings too. That’s the point at which I realised I’d need some kind of stack and parsing and grammar so after 3 seconds on Google, I found fnmatch. It’s times like this you wonder why you didn’t just look this up in the first place.

Leave a Comment

Menus in Gvim under Ubuntu 11.04 (Natty Narwhal)

The text editor Gvim has menus that aren’t compatible with the new Unity window manager in Ubuntu 11.04 (Natty Narwhal). To get around this, you can tell Ubuntu to fall-back to the old Gnome style menus by setting the UBUNTU_MENUPROXY environment variable to null:


UBUNTU_MENUPROXY= gvim filename.ext

 

Leave a Comment

DRBD

DRBD (Distributed Replicated Block Device) is one way to implement warm standby on Linux systems by replicating an entire disk partition over the network. As changes are made to the master server, the secondary servers are kept in sync. If there’s a failure, you can bring up one of the secondaries.

I’ve been playing with DRBD at work today and found it pretty simple to configure using the instructions in The Ubuntu Server Giude

The most hassles I had were that I put data on the partition before I set up DRBD so I had to resize the filesystem to make room for the metadata block that DRBD wants to put at the end of the partition. This was not a big deal either in the end and there is actually an option to put the metadata elsewhere.

We have some scripts here at work that manage bringing up any services that need the drbd partition to be mounted. Note that the mounted device is the /dev/drbdN device, not /dev/sdaN. Unfortunately I can’t publish them here but it is not too difficult to write one. The basic concept is to put the sys V rc style links in a different directory and loop through them once DRBD is online. In our case we have the database on the DRBD partition so we don’t have to muck around with a separate database replication service.

DRBD might even be a decent solution for offsite backups if you have admin rights on both hosts. Just keep everything you need to keep backed up on a special partition and it will sync in the background (It looks like there’s a setting to throttle the bandwidth).

One limitation is that you can’t mount the partition on the secondary drbd nodes. You have to make them primary first and then you can mount them. I see that’s it’s possible to have dual primary nodes though.

Another gotcha seems to be that you must have drbd running to read from the partition so you can’t just grab the backup disk and boot from it.

Leave a Comment

Fastest ever Boot of Embedded Linux: 300 ms

Not bad: http://lwn.net/Articles/435854/ (may be behind paywall) or http://article.gmane.org/gmane.linux.embedded.celinux.devel/100


From: Constantine Shulyupin
Subject: Fastest ever Boot of Embedded Linux: 300 ms
Newsgroups: gmane.linux.embedded.celinux.devel
Date: 2011-03-28 20:40:42 GMT (3 days, 9 hours and 30 minutes ago)

Hello all,

Make Linux Software presents the fastest ever embedded Linux boot for 720 MHz ARM and NAND flash memory. Linux boot time is 300 milliseconds from boot loader to shell. The first goal of the project is to achieve a minimal boot time of a minimal but functional Linux system on common hardware. The second goal is to provide a platform for developing more
functional systems with an even minimized boot time.

Video of boot process: http://www.youtube.com/watch?v=747XLVbTgA4

Boot log with timestamps:

0.000 0.000: TI X-Loader 1.4.4ss Mar 26 2011 01:45:43
0.000 0.000: Optimised by www.MakeLinux.com
0.000 0.000: Loading
0.237 0.237: Running
0.237 0.000: CFG_LOADADDR=80008000
0.249 0.012: (int)CFG_LOADADDR=e321f0d3
0.276 0.027: Linux version 2.6.32 (const@...)
0.276 0.000: Starting application
0.296 0.020: BusyBox v1.16.2 hush – the humble shell

To learn more, please visit http://www.makelinux.com/emb/fastboot/omap

Thanks.


Constantine Shulyupin
http://www.MakeLinux.com/
Embedded Linux Systems,
Device Drivers, TI DaVinci

Leave a Comment

Console on framebuffer ivtv tvout

I haven’t got this working at all yet. What I’m trying to achieve is the linux kernel console using ivtv framebuffer and tvout so I can CTRL-F1 and see the console on my TV and also keep an eye on the console while booting my mythtv.

I followed this guide: http://www.savvyadmin.com/console-framebuffer-in-ubuntu/ and used this table of grub vga options: http://techpatterns.com/forums/about342.html

No luck so far.

Leave a Comment

Using udev to make sure my webcam always has the same device name

On ubuntu, I added a new file /etc/udev/rules.d/50-webcam.rules


SUBSYSTEM=="video4linux" ATTR{name}=="OV511 USB Camera" SYMLINK+="ov511_webcam"

 

As you would find after reading this helpful udev guide the above rule causes udev to match any devices in the video4linux subsystem that have a name attribute set to “OV511 USB Camera” and create a symlink /dev/ov511_webcam pointing to the real device whatever that might be. I could have also forced it to name the device /dev/video1 using the NAME= command instead of SYMLINK.

Thanks to Florian Kulzer and Nigel Henry on this debian support thread for the help.

Leave a Comment