Log <-

Archive for the ‘linux’ Category

RSS   RSS feed for this category

Excluding results of a 'find' command (inverting tests)

Tuesday, November 10th, 2009

In kind of a follow up to my previous post on using find and sed to search and replace multiple files, I found out something else.

I needed to find and replace something in every file, except for any files which had ".svn" in them. After struggling for a few fruitless minutes with -regex, I stumbled upon this example in the manual page:

find /sbin /usr/sbin -executable \! -readable -print

   Search for files which are executable but not readable.

The \! allows us to invert the tests after it. Perfect! All we need to do is use -regex to do our excluding:

find . -type f \! -regex ".*\.svn.*"

And we can now search and replace in all files except those that have ".svn" in them:

find . -type f \! -regex ".*\.svn.*" -print0 | xargs -0 sed -i "s/foo/bar/"

Neat. Note that, again, -regex is a GNU find only construct.

Linux search and replace

Monday, November 9th, 2009

I always kept a small Python script around for searching and replacing in Linux. Turns out that GNU sed has an inline edit mode which I didn't know about:

       -i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if extension supplied)

This makes searching and replacing in files as simple as:

find . -name "*.txt" -print0 | xargs -0 sed -i "s/foo/bar/"

This replaces all occurences of "foo" with "bar" in all the .txt files in or below the current directory.

Unfortunately, -i appears to be a GNU extension, so it won't work on *BSD or Solaris, probably.

Debian: MAC address changes: interface changes

Thursday, October 8th, 2009

Since Debian 4.0 or some such, when your MAC address changes, your interfaces changes too. So if you spoof the MAC address of your nic, or you clone a Debian 5.0 VirtualBox guest and assign it a new different random MAC address, or if your nic broke down and you replaced it, the new nic will be assigned to eth1 instead of eth0 (if you previously only had one network card in your machines, that is). Chances are your statically defined network settings (in /etc/network/interfaces) will not work anymore, because they refer to eth0, and not to eth1.

The reason behind this appears to be Udev. It keeps a list of MAC addresses and which interfaces they were assigned to, and when it sees a new MAC, it assumes that is a new network card, and so assigns it a new ethX interface. This is both a good thing, as it will keep your system from rearranging all the nic's if you add one or one dies, and a bad thing, as your network will not come up anymore if you've replaced the previous nic

To fix this, log in at the console as root, find a file named something like persistent-net.rules in the /etc/udev/rules.d/. The file may be prepended with some and remove all the lines in that file below the You can modify it... line.

When done, reboot. (I haven't yet found out how to regenerate the file. Running the executable the file mentions doesn't work for me).

Software Bashing

Thursday, September 3rd, 2009

We started a new site where we can vent our rage on all things sucky about software:

Software Bashing: We hate software. With a passion:

Fact: All software sucks. We're here to show you exactly why, and just how much it truly sucks. We don't discriminate against vendor or development model; all software sucks. We are relentless. We show no mercy. If the software exists, we will find its suckage, no matter how much it leverages synergetic business potential. Be prepared.

Hopefully we can reach some software authors and make them see the light. If not, at least I was able significantly reduce my blood pressure through the site.

Ubuntu sucks!

Sunday, April 19th, 2009

I used to be real pleased with Ubuntu, because it got a couple of things right that Debian didn't. But I've upgraded my Ubuntu install three times now, and every time I upgraded everything broke.

The last time I upgraded, everything even remotely having anything to do with sound broke. This was because the geniuses at Ubuntu decided to include the shitty PulseAudio sound architecture in Ubuntu way before it was ready to be included. (Yeah, I know, not really PulseAudio's fault, but I'm just trying to get the PulseAudio crowd pissed at the Ubuntu crowd in the hopes that they'll gun them down).

Last time I upgraded, from Hardy to Intrepid, all my sound stuff broke again, flash didn't work anymore, my wireless broke (I've kind of fixed it now, but now NetworkManager keeps dropping the wireless connection when I push too much data through it, and can't get up again without a reboot – piece of shit), my hotkeys and all my keybindings broke, my sessions weren't saved anymore, my sound applet refuses to address the right mixer channel, my ~/.xinitrc is being ignored, I can't rm -rf / anymore (my favorite past-time thing in Linux :-( ).

Each time I upgraded Ubuntu, I found myself doing a clean install a couple of days later because too many things had broken. And even after that, many of the broken things were still busted.

I've had it with Ubuntu. It's a piece of shit. I'm going back to Debian Stable.

Terminator – Splitting Terminal Emulator

Monday, January 12th, 2009

I use terminals a lot. Some years ago, there was a terminal emulator called Gnome-multi-terminal, which could be split horizontally and vertically, and thus giving optimum workspace usage when using many terminals. Gnome-multi-terminal wasn't being maintained anymore (or at least not regularly) and started displaying some buggy behaviour in newer versions of Debian and Ubuntu.

I've searched for a replacement for a long time, but was never able to find one. Now I finally have: Terminator.

Here's a screenshot:

.

Nice :)

Wednesday, October 29th, 2008

This is nice: I would just like to say….

Apache 2.2: Multiple authentication providers

Friday, October 24th, 2008

For a long time Apache only supported a single authentication provider per location. For instance, you'd have:

<Location />
    Require valid-user

    AuthType Basic
    AuthName "FooCoorporation"
    AuthBasicProvider ldap

    AuthzLDAPAuthoritative Off
    AuthLDAPURL ldap://192.168.1.1:389/ou=foo,o=electricmonk,c=nl
    AuthLDAPBindDN cn=ldapreader,o=electricmonk,c=nl
    AuthLDAPBindPassword PASSWORD
</Location>

In older Apaches, it wasn't possible to add another Authentication provider. So, in the situation above, you can run into problems when your LDAP server dies on you, and you won't be able to login to the / location anymore until the LDAP was fixed. Another problem with single authentication mechanisms is that there's no way to add authenticated users if they're not in the LDAP.

Since Apache 2.2 multiple authentication providers are now supported. This is nice, since now you can have an LDAP authentication provider with an htpasswd fallback authentication mechanism.

You can enable it by specifying multiple AuthBasicProvider providers:

    AuthBasicProvider ldap file

So the full Location section becomes, for example:

<Location />
    Require valid-user

    AuthType Basic
    AuthName "FooCoorporation"
    AuthBasicProvider ldap file

    AuthzLDAPAuthoritative Off
    AuthLDAPURL ldap://192.168.1.1:389/ou=foo,o=electricmonk,c=nl
    AuthLDAPBindDN cn=ldapreader,o=electricmonk,c=nl
    AuthLDAPBindPassword PASSWORD

    AuthUserFile /var/www/.htpasswd
</Location>

Transmission 1.x on Ubuntu 7.10

Sunday, February 17th, 2008

For some reason Ubuntu 7.10 has an ancient version of Transmission. Version 0.74 or somesuch. Unfortunately, that version of Transmission contained some bugs so it's blocked by certain bittorrent trackers. In order to install a more recent version:

You can download a more recent version from the gutsy backports package pool.

  • Uninstall transmission:
    sudo aptitude purge transmission transmission-gtk
  • Download transmission-common 1.04
  • Download transmission-gtk 1.04
  • Install the packages:
    sudo dpkg -i "transmission-common_1.04-0ubuntu1~gutsy1_all.deb"
    sudo dpkg -i "transmission-gtk_1.04-0ubuntu1~gutsy1_i386.deb"

And you'll have a more recent version of Transmission.

DVTM – dynamic virtual terminal manager

Monday, February 11th, 2008

I do a lot of remote UNIX administration on various servers and even some desktop machines. This usually means that I'm doing a lot of SSHing into machines, often opening multiple sessions to the same machine at the same time. It quickly becomes tedious to keep having to type 'ssh fboender@some.machine.com' four times in order to get four sessions.

Of course there is Screen, but Screen's split screen abilities are very limited and don't really work for me. While scanning Freshmeat.net, I found a tool called DVTM: dynamic virtual terminal manager.

DVTM
DVTM is a kind of window manager for the console (or xterm) which allows you to quite easily split your terminal into multiple split screens.

DVTM has some limitations though:

  • Configuration is done using C code. (Though you'll probably never need to change anything; the defaults are quite sane)
  • It doesn't seem to support ANSI colouring. I use a red background at my prompt when I'm root, which I now have to miss.
  • It also doesn't seem to support line-drawing. This probably has something to do with the terminal type.
  • DVTM has no internal support for detaching and reattaching to running DVTM instances like Screen can. (But see the Tips and tricks section on the homepage).
  • There are a couple of small bugs, one of which is a problem with repeating keys when switching between split windows with the mouse.

But make no mistake: despite these shortcomings, DVTM is an absolutely fantastic tool. Some of the neat stuff it supports is:

  • Mouse support for switching between split windows / maximizing and unmaximizing, etc.
  • Maximize/unmaximize the currently active window (Default: Ctrl-g m / Ctrl-g g)
  • Various window layouts (you can probably add your own by hacking the source code)
  • Almost no dependencies except for ncurses.

The only thing I'd really like to see changed about DVTM are custom run-time splitting (for instance, Ctrl-g-MINUS to split the current window horizontally and Ctrl-g-PIPE to split the window vertically) and detaching/reattaching.

All in all, DVTM is an awesome tool. Go download it if you do a lot of remote administration.

Update: There also appear to be two bugs:

  • On the latest Ubuntu: Sometimes when exiting DVTM, it will hang for a while, and the cursor will blink like mad. An strace shows that IO Errors are occuring on file descriptor 3. I've filed a bug report with the author. This bug doesn't appear on Debian stable.
  • When using DVTM in combination with dtach, reattaching doesn't redraw the screen. This appears to be a problem with DVTM, but it would probably be easier to solve in dtach (which could just signal a screen resize event without actually resizing the screen). This is also the workaround for this bug: just resize the window. I'll see if I can file a bug report with either DVTM's author or dtach's author.

Update II: Here's a little patch/workaround for the first bug (exiting DVTM hangs for a while):

--- dvtm.c      2008-02-06 17:30:25.000000000 +0100
+++ ../dvtm-0.4/dvtm.c  2008-02-11 23:33:45.000000000 +0100
@@ -896,6 +896,7 @@
                Client *c;
                int r, nfds = 0;
                fd_set rd;
+               struct timeval tv;

                if(need_screen_resize)
                        resize_screen();
@@ -996,6 +997,13 @@
                        wnoutrefresh(sel->window);
                }
                doupdate();
+
+               // One microsecond delay so this loop doesn't hang context-switching
+               // when the last child dies and the SIGCHLD signal is prevented from
+               // being caught on time.
+               tv.tv_sec = 0;
+               tv.tv_usec = 1;
+               select(0, NULL, NULL, NULL, &tv);
        }

        cleanup();

Save to ~/patch.diff and in the dvtm-0.4 directory run:

~/dvtm-0.4$ patch -p0 < ~/patch.diff

Update III:

I was incorrect in stating that dvtm doesn't support ANSI coloring. It's just the bash prompt which doesn't work. Perhaps because there is a Xterm-styled window title ANSI sequence in there. Will update when I know more.

Update IV:

Marginally better patch:

diff -Naur ./dvtm.c ../dvtm-0.4/dvtm.c
--- ./dvtm.c	2008-02-06 17:30:25.000000000 +0100
+++ ../dvtm-0.4/dvtm.c	2008-02-12 22:08:54.000000000 +0100
@@ -982,7 +982,10 @@

 		for(c = clients; c; c = c->next){
 			if(FD_ISSET(c->pty, &rd)){
-				madtty_process(c->term);
+				if (madtty_process(c->term) < 0 && errno == EIO) {
+					/* client probably terminated */
+					client_killed = c;
+				}
 				if(c != sel){
 					draw_content(c);
 					if(!isarrange(fullscreen))