Screen in Ubuntu Karmic

I have written about screen quite often, mostly including my .screenrc file and showing how to have named tabs for the various screen tabs you have open. When Ubuntu Jaunty came out, I found it had some quite cool enhancements that made the customisations for screen really easy by default – and I wrote about these.

In Karmic Koala, Ubuntu 9.10, the packages are still there but they’ve changed names! So if you want to use screen with Ubuntu Karmic or later, install packages byobu and byobu-extras, and uninstall screen-profiles and screen-profiles-extras (they were broken on my system after upgrade anyway) and you should find everything works as expected. To run screen with the new features, you should run “byobu” instead – although screen commands seem to work to detach and reattach the screens that result, weirdly.

I’m mostly posting about it because I have been very frustrated and there’s no way I could have guessed, or probably ever will remember, what these packages are called. Apparently a byobu is a japanese room screen … you learn something new every day!

Sound Issues with Kubuntu Karmic Koala

Since upgrading my work machine to karmic koala, I’ve noticed that my sound had stopped working. There were some broken packages in aptitude and Skype knew there was a problem as it notified me when I tried to make a call. I saw some issues reported with karmic, notably this one, so I uninstalled pulseaudio

sudo aptitude remove pulseaudio

When I restarted Skype, everything seemed to work as expected – for reference I have a thinkpad T400, if you’re having the same issues, then hopefully this will help!

Customising Screen-Profile Files

I wrote a while ago about the new version of screen in Ubuntu Jaunty. Screen is an application which lets you run lots of tabs inside one terminal window, then disconnect from screen and reconnect again later. You can turn on and off a whole bunch of notifications which appear inside screen, and I also added the pink tabs I used with older versions of screen.

The tabs line is the one in the profile file which starts “caption always”.

caption always "%{wk}%H%{Bk}|%{Mk}%?%-Lw%?%{km}[%n*%f %t]%?(%u)%?%{mk}%?%+Lw%? %=%{Bk}"

I also altered the “hardstatus string” line, which holds lots of placeholders, to remove the clock – I run screen on my laptop inside KDE mostly, so I already know what time it is. Annoyingly this isn’t customisable via the menus but I edited my profile file to get rid of it – here’s the diff

29c29
< hardstatus string '%99`%{= kw} %100`%112`%= %102`%101`%114`%115`%108`%113`%119`%117`%118`%116`%106`%104`%103`%105`%107`%Y-%m-%d %0c:%s'
---
> hardstatus string '%99`%{= kw} %100`%112`%= %102`%101`%114`%115`%108`%113`%119`%117`%118`%116`%106`%104`%103`%105`%107`'

The only thing annoying me now is that screen seems to constantly redraw itself, so Konsole thinks there is activity in that screen, when there isn’t. Suggestions on stopping this or more ways you can customise your screen file are gratefully received – just add a comment!

Updating Memcached on Ubuntu Jaunty

I’ve been working with memcache-related things lately and ran into a problem where the library I was using just didn’t seem to do what its documentation said it would. It turned out that it was making a “gets” call rather than a “get” call – and this functionality wasn’t introduced to memcached until version 1.2.4. Closer inspection shows that although Ubuntu Jaunty Jackalope (9.04) is only a few months old, and memcached 1.2.4 is about 18 months old, its not included and Ubuntu versions Hardy, Intrepid and Jaunty all had 1.2.2 version of memcached.

Credit to the Ubuntu people for resolving this issue already – since memcached 1.2.8 is currently pencilled in for Karmic Koala release of Ubuntu later this year – but I can’t wait that long so I updated my own memcached, it was pretty easy so here are the steps in case anyone else wants to do the same.

  1. download memcached from http://www.danga.com/memcached/download.bml
  2. check you have the dependencies you need. The only thing I didn’t have was the libraries for libevent, which you can install through aptitude with aptitude install libevent-dev
  3. compile as you usually would: configure/make/make install

The final step is to get memcached running – I actually did aptitude remove memcached to get rid of my old version and stop myself from being confused later. Then to start it from command line I used:

/usr/local/bin/memcached -m 64 -p 11211 -u nobody -l 0.0.0.0

The above worked for me and allowed me to use the functionality available in the newer library (specifically I was looking to use the cas (compare and swap) functionality in the new PHP memcached extension) – it probably works on other distros too but I didn’t test it, if it works for you or if you have anything to add then please leave a comment!

Top Tips from Linux-Fu

I have recently been giving a talk entitled “Linux-Fu for PHP Developers” (slides are here) and although it includes some really basic commands, even some quite experienced people have thanked me for particular bits that they picked up. I’m considering dropping some of the sections from this talk so here are the things people most tell me they learned:

cd –

If you pass a single minus as the argument to cd, you will change back into the directory you just came from. Ideal for those switching-between-two-deep-links situations.

pushd and popd

I didn’t include these in my talk formally but I mentioned them almost every time I gave it (or one of the attendees did!). I don’t actually use these commands, but they are like an extension to “cd -” – you can build up stacks of directories and then jump around between them. They sound pretty handy so do take a look.

ls -lrt

I got a lot of negative comments for including “cd” and “ls” in my talks – but I had quite a few people say that the -t (to sort by time) and the -r (to reserve the sort) switches were new to . I use these together for viewing which files are new in a directory, great for logfiles or upload directories.

Hope these are helpful to someone, let me know if you use these or have others you’d like to share!

Linux-Fu For PHP Developers

The slides from my talk at php|tek are now online – Linux-Fu for PHP Developers. Thanks to everyone who attended and left feed back for me on joind.in. Feel free to leave a comment if you were there or if you have any questions about the slides!*

* Unless the question is “why didn’t you include X?” in which case the answer is that an hour-long slot was nothing like enough :)

Presenting Under Linux: xrandr

This is a mini-primer on using xrandr to configure a second screen under Linux, but first I’ll start with some background.

I’ve been a linux user for a few years now but when I started working for Ibuildings I started giving presentations, either as a speaker or when delivering training – and for a long time I used to boot into Windows for those, using a VM if I needed to code.

The main reasons I wasn’t comfortable using Linux to present were:

  • I have Powerpoint and I use the presenter view a lot
  • Linux doesn’t automatically find and configure monitors like Windows can.

Since Ubuntu Intrepid Ibex (8.10), its been possible to reconfigure screen in Linux without restarting X. But I was kind of scared of xrandr and I still liked the Powerpoint presenter view so I just carried on with windows. Then I realised that Open Office had also released a presenter view and I gave it a try. With one obstacle removed it was time to learn to work xrandr, which means I can also work external monitors without fiddling with xorg.conf, very useful. I’m now pretty confident with it so here’s the benefit of my wisdom*

xrandr

The first thing to do is figure out what you have and what your options are. So plug in the second screen and run xrandr with no arguments. On my system I get something like this:

Screen 0: minimum 320 x 200, current 1024 x 768, maximum 2560 x 1024
VGA connected 1024x768+0+0 (normal left inverted right x axis y axis) 338mm x 270mm
   1280x1024      60.0 +   75.0
   1024x768       75.0*    60.0
   800x600        75.0     60.3
   640x480        75.0     59.9
   720x400        70.1
LVDS connected 1024x768+0+0 (normal left inverted right x axis y axis) 304mm x 190mm
   1280x800       60.0 +   50.0
   1024x768       85.0     75.0*    70.1     60.0
   832x624        74.6
   800x600        85.1     72.2     75.0     60.3     56.2
   640x480        85.0     72.8     75.0     59.9
   720x400        85.0
   640x400        85.1
   640x350        85.1
HDMI-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)

This shows VGA (your external output) and LVDS (the laptop screen) and all the various modes they support. I sometimes see output under HDMI-1, and this seems to cause problems so I always turn off this output by running:

xrandr --output HDMI-1 --off

Next I send a command to set the resolutions on both screens. For projectors I tend to go with 800×600 as this almost always works and it means the text on my laptop screen is then so large I can see it from several feet away!

xrandr --output LVDS --mode 800x600 --output VGA --mode 800x600

Its perfectly fine to have different resolutions on both machines but bear in mind that X has one desktop and will show you sections of it on each monitor so if they’re different sizes you sometimes get either bits missing off one monitor or one of the outputs looks stretched. I don’t really have any general advice with this other than get the projector in the right ratio and then fiddle with the available modes to see what works for you.

To set the second screen to be different from the first (i.e. tiled rather than mirrored), just tell xrandr where you want it.

xrandr --output LVDS --mode 1280x800 --output VGA --mode 1024x768 --right-of LVDS

Again you’ll get sections of a single desktop, not two separate areas, so things might look odd if they are on both screens. For me this command has worked really well since I got to grips with it in the last few months, and I’ve plugged various machines in to various external monitors and given a few different talks. I’m sure there is a lot more to know about xrandr but I haven’t needed it yet – hope this is helpful! If you have any experiences with this or anything to add, just drop a line into the comments form.

* I’m not an expert by any means, but the above works for me on Ubuntu with my Thinkpad T400 and my Acer Aspire One.

Screen-Profiles – Improved Screen in Ubuntu Jaunty

I recently upgraded my kubuntu installation to 9.04 “Jaunty Jackalope”. It turns out that they have added some very cool features to screen in this version. If you don’t use screen its its worth finding out more, certainly its a tool I now can’t live without.

The first thing to say is that if you have an existing .screenrc file, you don’t get any notification or prompt about the new features of screen, I was lucky and fell over the information. To get to the features:

  • if you have a .screenrc, rename it for a moment
  • aptitude install screen-profiles screen-profiles-extras
  • run screen

EDIT: From Karmic Koala (9.10) and later these packages are now byobu and byobu-extras – they work as outlined here however, just the package names changed.

The first thing you’ll notice is that there’s a whole lot more stuff going on at the bottom of the screen. I have had a custom .screenrc file which gave me tabs for a while, but now they’re part of the standard setup.

If you look in the bottom right corner you’ll see there’s an “F9 Menu” – yep, screen responds to a whole bunch of function keys! I’ll keep my traditional ctrl+a mapping I think, but you can reconfigure this to your hearts content. And look at the menu itself:

You can change the colour themes (more on that another day, I’m still playing with the settings) and you can also turn on and off a load of different widgets, basically lots of different system information. I’ve got most of it turned off on my laptop (since I already have a battery meter etc) but for a server this could be really useful. Examples:

I’m really happy to see Canonical improving this particular tool, and I wanted to mention it purely because existing users of screen won’t see the new functionality by default which seems like a bit of an oversight. If you’re a screen user, upgrade to Jaunty, try it out, and leave a comment on how it works out for you.

Kubuntu Freezing on Splash Screen after Jaunty Upgrade

Today I upgraded a bunch of machines to the latest Kubuntu offering, version 9.04, or “Jaunty Jackalope”. Well, it was all going a bit too well and when I came to upgrade my main work machine, a thinkpad T400, I ran into problems. There are a couple more kinks but I had one particular error which I wanted to blog about. When I upgraded and then restarted Kubuntu, it froze on the splash screen after showing three icons (up to the globe).

The problem was that the files in the ~/.ICEauthority directory were owned by root so couldn’t be written to by my user. I followed the instructions I found on this post where someone had exactly the same problem, and just chowning the whole directory to my user fixed the problem and allowed me to boot Kubuntu.

Hopefully if anyone else has this problem they’ll find either this post or the other one and also find the easy fix! If this works for you, leave a comment.

Quiet Diff

I recently saw a problem that we were having difficulty replicating, despite assurances that both the code base we were replicating on and the one that exhibited the error were identical. They are large codebases and when I got copies of them both I tried to check for differences:

diff -ur dirA dirB

The result was large and messy and included a lot of .svn files (long story). So to get an idea of how many files had differences I ran diff with -q for Quiet. This just outputs one line per changed file and also a line for if a file only exists in one or other directory. I then used grep to ignore any lines with .svn in them, and finally passed the whole lot to wc (for Word Count) to tell me how many lines there are.

diff -urq dirA dirB | grep -v .svn | wc -l

If you get a number greater than zero, your codebases are not identical and you have discovered why your fault is “intermittent”.