Day 4 – Falling back to the meta-referance
Last night I posted on twitter that I was struggling to find stuff to post about. jkblacker (Not bassets, sorry Josh!) suggested that I post about how I’m finding it hard to find stuff to post about… so here it is
Not exactly the most spectacular day 4, especially since I’ve got 26 left to go, but we’ll see what happens.
Parts for my new computer started arriving today. I’d hoped that it would all arrive, but unfortunately not. So, right now I’ve got RAM, the PSU, Motherboard, CPU cooler and a copy of Windows. (Yes, I know, horrible, but I’m building a gaming machine, wine isn’t there yet, and Linux hasn’t reached critical mass
)
Sporadically over the past week or so, I’ve been trying to use search and replace in vi/vim. Finally got it drummed into my head! Here’s the syntax for single item search and replace:
:%s/OLDSTRING/NEWSTRING/
If you want to replace every item in a document, then add “g” to the very end. “g” in this context means “greedy” – i.e. replace everything. (Thanks JPE – I did learn it after all!)
This is the same sort of syntax as usable in the command line tool “sed”. For example, if you wanted to replace a space in a file with a comma, then you’d do:
sed 's/ /,/g' oldfile > newfile
I’m sure there’s a better way to specify that syntax… please feel free to comment
Firefox won’t upgrade!
Firstly, apologies about the lateness of writing a new post. I’ve been struggling with my server, trying to work out why apache2 is eating RAM. I’ve made a really nasty hack to sort it out for the moment though, which will give me more time to find out what is going wrong.
One of my old friends from Church sent me an email, asking me what was wrong with his firefox. Every time he launched it, what appeared was firefox 2. Very strange, since the version of firefox he has installed is:
3.0.1+build1+nobinonly-0ubuntu0.8.04.3 - meta package for the popular mozilla web browser
Well, that looks like the normal browser to me. At one point, he has had the “ubuntuzilla” browser installed for a little while. (But not anymore).
A couple of questions on the Ubuntu-uk mailing list didn’t turn up anything. So, I asked “how do you find what binary a command runs”? The answer came back from Matthew Wild (thanks!):
ls -l $(which firefox)
I cheated a little. I’ve not come across $(command), but I have come across `command`. So, I asked my friend to run “ls -l `which firefox`”. He replied with:
lrwxrwxrwx 1 root root 20 2008-02-09 17:16 /usr/bin/firefox -> /opt/firefox/firefox
Er.. that looks wrong to me. The packaged firefox binary for version 3 is in /usr/bin/firefox-3.0. Looks like the uninstall of ubuntuzilla didn’t go so well. I asked him to run:
"rm /usr/bin/firefox && ln -s /usr/bin/firefox-3.0 /usr/bin/firefox"
Which removed the old link, and added the correct one. (I should have asked him to run those commands through sudo thinking about it..)
That solved his issue and he’s now happily running firefox 3. Anyone have a better way to implement this fix, if we ever need it again?
Matthew kindly explained the difference between “$(command)” and “`command`” in earlier today. No difference
$(command) is easier to send to people so they don’t have to find the backtick key. (UK keyboards, above the tab key)
Hidden Ubuntu Gems: Window Selection, Always on Top & Password Gen
I thought it was probably a good time for another Ubuntu-related post, so here we go.
Window Selection
Something I found on one of my explorations, is this really handy feature (handy for me at least), which allows you to give a window “focus” (or selection) merely by putting your mouse over it. To activate it, click on “System”, go to “Preferences”, and then click on “Window”. Up pops a small selection window.
As you can see, I’ve ticked “Select windows when the mouse moves over them”. You can also have windows be raised to the top of the screen if you hold your mouse over them for a certain length of time. As my collegue at work found, setting the interval to “0″ is not very useful…
There are a couple of other tweaks you can make here. I’ll let you explore them on your own
Always on Top
“Always on Top” allows you to basically tell the system that you want a window to be the upper-most on the screen, no matter what else you do. You can’t “Raise” anything above it. I tend to use this little gem with my next tip.
Set a window to be always on top by right clicking on the title bar (the big orange bar at the top of the window, which contains the minimize, maximize and close buttons). Click the “Always on Top” option. That window will now stick on top of your screen. Undo it, by right clicking again on the title bar, and clicking “Always on Top” again.
Password Gen (pwgen)
pwgen is a small, neat, command-line program to quickly generate fairly easy-to-remember, fairly secure passwords. You can install it by clicking here, or going to whichever package manager you prefer (synaptic, Add-Remove Programs, apt-get or aptitude) and installing “pwgen”.
Use it simply by typing “pwgen” in a terminal (“Applications” > “Accessories” > “Terminal”). I tend to run it with the command “pwgen 8 1″, which generates one 8 character password.
Now, if you’re adding a lot of users to a system or something (I am currently at work), using a combination of these tips will save you time… I’ll leave it up to you to work out how to combine them. (Hint: resizing a terminal window like I did above is a good starting point.)
Notes / MySQL Transactions
Why should you not use your notepad as a coaster? This is why:

The notes did say this, before my lovely hot black coffee destroyed them:
| “begin” | == Start transaction |
| “commit” | == End transaction, saving all changes |
| “rollback” | == Undo all changes that you’ve made in the transaction |
What are they? In mySQL 5, with a table storage type of “innodb” you can use transactions. This means, that you can make a set of changes together, like recording the removal of a credit, and the adding of an advert to a website, at one instance, even if it’s multiple mysql transactions within one connection.
You do that, by sending the command (literally “BEGIN;” or “begin;”) to start a transaction, run all the queries you need to run, and then run the commit if you want the all the changes to take, or rollback if you don’t. If any one of the sql queries fails after you’ve made a begin, and it shouldn’t have, you can rollback *all* the changes you’ve made to the database. Obviously, this needs one mySQL connection, but if you’re using more than one each run of the program you’re using, I’d be very surprised.
Xen Gutsy Links
A post full of links and unsorted info about using Xen on Ubuntu Gutsy Gibbon, so that I don’t forget. (This lot has taken ~2 days to collect…) May make a full howto sometime… probably not though, as my boss knows this stuff better than I. Xen is pretty cool though…
https://help.ubuntu.com/community/Xen (useless for gutsy…)
The Xen console doesn’t work (xm console <domU>), network works once, and then never again… Going to paste this here as its in a pastebin, not sure when it will expire… (Have tweaked slightly, snipped a couple of things out, added couple of things in)
http://rafb.net/p/49Ku5e10.html
>> OK, I have made a little progress on this. I mounted my VM image on a
>> loopback and chroot'd to it. I opened /etc/init.d/hwclock.sh
>> and /etc/init.d/hwclockfirst.sh and added the following to the top of each
>> file:
>>
>> exit 0
ALSO SEE: http://lists.cvsrepository.org/xen-tools/Jul07/0332.html
sudo xm create -c </path/to/config/file>
-----------------
# Ever-increasing network device names?
# Just disable the correspondent udev rules by deleting/renaming your
/etc/udev/rules.d/<NUMBER>persistant-net.rules. (number was 70 for us...)
guest# mv /etc/udev/rules.d/{,.}z25_persistent-net.rules
# And then make sure your vif (in your instance config file) contains your mac
# address like:
vif = ['ip=192.168.0.45,mac=<random valid mac addy>']
Just be sure to stop the instance (domU), and then restart (re-create) it again when needs be…
Also, when in the Xen console, try hitting enter before using the escape sequence (CTL +]) if it’s not working. Sometimes it enters into the console after the “login:” prompt has been printed, and doesn’t seem to pick up that its just had a new connection…
The ALSO SEE link: http://lists.cvsrepository.org/xen-tools/Jul07/0332.html
Using Serial console & xen console (serial console conflicts with xen console):
http://phaq.phunsites.net/2007/06/30/xen-console-grabbded-devttys0
/boot/grub/menu.lst stuff, to enable us to use a serial console as well as xen:
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 terminal --timeout=2 serial console
Goes in the top of your menu.lst, outside the automagic sections…
## additional options to use with the default boot option, but not with the ## alternatives (These options are not used with the Xen Kernel!) # defoptions=quiet splash console=ttyS0,115200n8
For the default kernel, (NOT the xen kernel).
Goes inside the AUTOMAGIC section of your menu.lst, adding to the options already there.
## Xen Linux kernel options to use with the default Xen boot option # xenkopt=console=tty0 console=ttyS0,115200n8 xencons=ttyS9
Note the xencons=ttyS9. Use a serial port (ttyS<No.>) that doesn’t already exist.
Your Xen kernel definition should look something like this, after you’ve run “update-grub”:
title Xen 3.1 / Ubuntu 7.10, kernel 2.6.22-14-xen root (hd0,0) kernel /xen-3.1.gz module /vmlinuz-2.6.22-14-xen root=/dev/mapper/volume-root ro console=tty0 console=ttyS0,115200n8 xencons=ttyS9 module /initrd.img-2.6.22-14-xen quiet
The guys on irc ##xen @ freenode are really helpful…
Useful Linux (Ubuntu) Tidbits
Here are just some morsels of information about the Linux Command line, and more specifically, Ubuntu Linux Command line / system.
- Users can be added to a group with the command:
sudo adduser <username> <groupname>
In ubuntu, the default system shell is “Dash”. That does speed up your system boot, but it also introduces problems with those scripts which are designed to run in bash, but use /bin/sh to execute. (Which is a surprising amount… this has solved many problems for me. Especially with Asterisk and freePBX.)
- To set Ubuntu back to using bash from dash, run the following command…
cd /bin && sudo rm sh && sudo ln -s /bin/bash /bin/sh
- To add a user to the sudoer list (the list that controls who can use “sudo”) use the command
sudo visudo
- Add a user underneath the “# User privalage specification” comment. If you want just a bog standard sudo user, able to do all on the system, add the line:
<username> ALL=(ALL) ALL
- ?Fun? tip: add “insults” to the end of the list of “Defaults” in visudo, so it will look like:
Defaults !lecture,tty_tickets,!fqdn,insults
- The system will insult you every time you enter your sudo password wrongly. For a random example, it just gave me this when I deliberately triggered it:
You speak an infinite deal of nothing
- In Firefox, select the address bar quickly by hitting the “F6″ key.
- Type “pwd” to get the full path to your current directory. e.g.:
kirrus@asus:~$ pwd /home/kirrus
- Monit is a useful program, that gives you a good way of keeping an eye on your servers, making sure they don’t run out of harddisk space, or get a high CPU load. It can either perform some function (like stopping a program from running) during high CPU, or send you a warning email.
http://debianhelp.co.uk/monit.htm (useful howto/basic guide)
http://www.tildeslash.com/monit/ (main website)
Monit is in the ubuntu repositories:
aptitude install monit
How to Configure or Disable Predictive Text in Open Office
Open Office keeps automatically trying to guess what you’re typing? Sometimes it can be useful, especially if you’re doing something quite repetitive. However, it can also be a bit dumb at times.
Now, Open Office predictive text, actually comes under auto-complete. Don’t ask me why, as to my mind at least, that’s a completely illogical place to put it. Also, Open Office call it “Word Completion”
Configure Open Office Predictive Text
Here are a couple of things you can try to make it more useful.
Click on “Tools” > “AutoCorrect…” > Click on the “Word Completion” tab.
- Increase the minimum word length.
Make sure that the minimum word length is at least 8. Less than that, and you’re going to get it trying to auto complete too-short words, and get confused. More than 8, it will trigger less often. Tweak this for how much you want to use the predictive system.
- Delete False Positives
Sometimes, the predictive system just gets confused. An example of this, is if you have used “Disneyland” in a document, and then want to type “Disney” Open Office will keep auto-completing to “Disneyland”. Really, not helpful.
To fix this the only response, is to find and delete the offending word from the predictive system. Click on the word you want to remove (In this case, Disneyland), and click the “Delete Entry” button.
Note: The image has been cropped to make it fit. The dialogue box is longer than this.
Disable Open Office Predictive Text
If you just can’t get it quite to work how you want, then your last resort is to disable the feature. Click on “Tools” > “AutoCorrect…” > Click on the “Word Completion” tab.
Now, untick the box that says “Enable Word Completion”. Your Open Office will no longer automatically try to predict what you’re typing.
Note: if you leave “collect words” ticked, the system will still collect words to Auto Complete, but won’t actually use them. If you’re just turning the feature off for a little while, leave it ticked. Otherwise, untick it, to save memory, and a little bit of processor power whilst you’re working.

How to turn a Ubuntu Box Brainless
WARNING: This will disable GUI access to your computer! DON'T do this to a machine which you want to use without having to play around with the X configuration files in command line.
In ubuntu, you can switch all logins to XDMCP quite simply. Here is the Howto:
- Click on System > Administration > Login Window
- Enter your password (if requested)
- Click on the security tab
- Click on the “Configure X Server” button in the bottom right hand corner of the window. This pops up:

- Change the “Launch” value from “Greeter” to “Chooser”
- Click close twice, and log off
- Hit CTRL – ALT – BACKSPACE together, to restart GDM. You should now have a XDMCP host searching window, which will locate any computers which have had XDMCP logins activated. If you want a howto for setting up a server for that, please comment!
Useful Ubuntu Things to Remember
- Firstly, when doing hardware maintenance, remember to plug all leads back in. (I’m so glad I’m not the only one who’s forgotten this: http://err.no/personal/blog/tech/2007-02-06-12-38_powerless_disks)
- To open a terminal in Ubuntu, go to Applications > Accessories > Terminal
- To add shortcuts from the applications listing to your desktop or top/bottom panel, browse to the location of the program under applications, click on it DON’T LET GO, and drag it to the bar at the top, or onto you desktop. Let go.
- To run a unattended upgrade on an (K/X/U)buntu machine use the following command in a terminal:
apt-get update; apt-get upgrade -y
- If you only want the upgrades to be downloaded, and not installed as well, then use this one (I think, this hasn’t been tested, and you could probably do it a bit more neatly with -dy):
apt-get update; apt-get upgrade -d -y
- Most linux variants store their programs (e.g. lspci) under /usr/sbin
- To force evolution (linux version of MS Outlook) to close completely, open a terminal, and run the following command:
evolution --force-shutdown
