Archive for the ‘Linux’ Category

PAE kernel breaks NVidia Drivers (Ubuntu)

Thursday, May 19th, 2011

I’m running on a ThinkPad T410 with 4GB RAM. I need to stay on 32-bit as I have some dependency on 32-bit applications that I couldn’t get running on 64-bit. Thus I’ve installed the PAE kernel to access all the RAM. Problem is, this broke the graphics.

After booting up the first time, I was presented with the option of running Ubuntu in low graphics mode – great.

Anyway, the fix is nice and quick. Go into the Hardware Drivers tool and disable the NVidia driver. Reboot – you should now be back to normal resolution, just no acceleration. Re-enable the NVidia drivers and reboot again and everything should be back to normal.

Fixing the aspect ratio on Canon camcorder *.MOD files

Saturday, April 2nd, 2011

I have a Canon FS200 digital video camera which creates MOD files.  These are playable on Linux by simply changing the file extension to “mpg”.  The only issue is that the video displays in 4:3 aspect ratio, whereas it should be 16:9.

On many players, you can override the display aspect ratio during playback and then the files display correctly.  The problem is when you want to edit these files or create overlay text/graphics, as the editing program will process them in 4:3 ratio, and then when displayed in 16:9, the overlays will look stretched (while the video looks correct).

Although I have tried to solve this a number of ways, the actual fix is remarkably simple and fast.  The clue to this fix was in the error message “ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.“.  Searching in the mencoder man page for “vprp” provided the solution.  Mencoder has a command line option “-force-avi-aspect” that can be used with the “-ovc copy” option, so you don’t need to re-encode (and potentially loose quality).  As this is only updating the meta data in the file, the fix is almost instantaneous.

The following command will perform the fix:

mencoder -oac copy -ovc copy -force-avi-aspect 1.777 input-4_3.mpg -o output-16_9.mpg

Ubuntu upgrade breaks LIRC

Saturday, January 8th, 2011

I recently upgraded my Ubuntu 10.04/XBMC based media center box (not a dist. upgrade, just a sudo apt-get upgrade).  After the update finished, I realised that the remote control (StreamZap) wasn’t working any more.

Quickly scanning the relevant files (i.e. /etc/lirc/* and /dev/lirc*) didn’t show up any obvious issues.

It turns out, all that is required is to run the following reconfiguration on lirc:

sudo dpkg-reconfigure lirc

Select your appropriate control and (if this doesn’t fix everything) then reboot and the remote should be working again.

UPDATE:

Unfortunately this seems not to be a permanent fix.  After rebooting, more often than not, the remote is not working again.  Performing the step above does seem to fix it for the current boot though.

A bit of further research found this post.  The post explains, that when the lirc_imon module is loaded (i.e visible when running an lsmod) the remote doesn’t work.  Performing the dpkg-reconfigure as stated above actually ends up removing the module lirc_imon – this is what actually fixes it.

So, to make the fix permant, you need to add lirc_imon to your modules blacklist.  The cleanest way to do this is to create another file called blacklist-lirc.conf in the /etc/modprobe.d/ directory with the following content:

blacklist lirc_imon

This will stop the module loading on boot, and your remote should remain working.

Connecting to MySQL database from OpenOffice.org Base

Sunday, January 2nd, 2011

Quick one here… if you want to connect to a MySQL database from OpenOffice.org Base, you need to install the openoffice.org-mysql-connector package:

sudo apt-get install openoffice.org-mysql-connector

After this is complete, make sure OpenOffice is completely restarted (i.e. not just the Base app, if you have a Writer window open, this needs to be closed too). Then just follow the prompts for connecting to an existing database (choose “MySQL” and “Connect directly” as you work through the wizard).

Running scripts on network connection (if-up.d, if-down.d,if-pre-up.d,if-post-down.d)

Friday, November 19th, 2010

On my previous post I described how to authenticate against web based logons after connecting to a particular SSID.  One of the problems I had was getting the script to actually run.  You should just be able to put a script in the /etc/network/if-up.d directory (on Debian based systems) and it should run when a network interface connects.  This wasn’t working for me and it seemed some other people were having issues too.

The solution to the problem turned out to be removing the file extension.  So the script that was named testscript.sh didn’t run, but the script named testscript did.  So if you are having similar problems you may want to try removing the file extension.

I am not sure if this is documented and expected behavior, or a bug.

Auto logon to web-authenticated wireless

Thursday, November 18th, 2010

At my current workplace I am using a guest wireless network.  After connecting, I need to open any web page and I am redirected to the login page and need to enter my provided username and password.  After submitting, I can browse any page and use the connection for email and other tasks.

Whilst this is only a minor inconvenience, it is definitely a candidate for automation.

A single line wget command is all we really need.  I have wrapped it up into a shell script below:

#!/bin/sh

username=XXXX
password=XXXX

wget -O /dev/null --no-check-certificate --post-data "username=$username&password=$password&buttonClicked=4&err_flag=0&redirect_url=google.com" https://1.1.1.1/login.html

-O /dev/null throws any downloaded content away, --no-check-certificate is fairly self-explanatory (wget wouldn’t connect to the https address without this), --post-data wraps up the various name/value pairs that the login form is expecting.

For most of these login forms, you only need a username and password, but I found with this one it also needed a few extra parameters.

So, the next step is to get this script to run automatically after connecting to the wireless network.  On Ubuntu (or any Debian based distro), there is a directory structure under /etc/network that includes an if-up.d directory.  Any scripts in here will be run after a network interface is brought online.  These scripts don’t have access to the SSID (as far as I know), but this can be obtained with the following command:

iwgetid --raw

Wrapping it all together, we can put the following script in the “if-up.d” directory:

#!/bin/sh

username=XXXX
password=XXXX
ssid=XXXX

if [  "`iwgetid --raw`" = "$ssid" ]
then
wget -O /dev/null --no-check-certificate  --post-data "username=$username&password=$password&buttonClicked=4&err_flag=0&redirect_url=google.com" https://1.1.1.1/login.html
fi

Remember to change the values of username, password and ssid.  Set the URL to the forms action value and add remove parameters as necessary.  Also, another point I learned the hard way is that the script can’t have a “.sh” extension, so name it “something” not “something.sh” (and remember to chmod +x it).

If you need to then connect to a VPN, this can also be added to the script.

Import contacts to Android (Sony Ericsson t650i to HTC Hero)

Friday, October 23rd, 2009

I am now the proud owner of an HTC Hero Android powered phone.  One of the first tasks to sort out was getting my contacts migrated.  What looked liked a problematic task at first has turned out to be quite simple.

My first instinct (as I had done this successfully with other phone migrations) was to backup my contacts to my SIM and then import them on the new phone.  This kind of worked, but was not too successful (i.e. surname, firstname back to front, other notes in weird places, not all numbers copied across).

Now to what did work.

From within the Sony Ericsson phone, I was able to back up my contacts to the memory card.  Following this I plugged in the SE phone via USB to my laptop, and copied the “PB_Backup.vcf” file across (found in the /media/PHONE CARD/system/pim directory).

Now to Gmail contacts.  Choose “import” and select your “PB_Backup.vcf” file.  If, after importing, this all looks ok, then sync your Hero (or other Android phone) and your done.  Contacts with the firstname first.

Fixing ThinkPad Trackpoint scrolling on Ubuntu 9.04

Monday, May 11th, 2009

Recently after upgrading my Thinkpad R52 to Ubuntu 9.04 I had some trouble configuring the trackpoint scrolling (one of the Thinkpad features that is hard to live without once you get used to it).

There are a number of blog posts and a good article on ThinkWiki that explain the cause of this (a move away from Xorg based input configuration to evdev).  But these solutions didn’t work for me.

After poking round for a bit, I started to realise there were some inconsistencies in the solution offered for evdev.  This was mainly in relation to the “axis” settings.  So I tried taking the solution offered on ThinkWiki and changing the  “Y” axis mapping to “Z” axis mapping as shown below. This file should be saved as “/etc/hal/fdi/policy/mouse-wheel.fdi".

<match key=”info.product” string=”TPPS/2 IBM TrackPoint”>
<merge key=”input.x11_options.EmulateWheel” type=”string”>true</merge>
<merge key=”input.x11_options.EmulateWheelButton” type=”string”>2</merge>
<merge key=”input.x11_options.ZAxisMapping” type=”string”>4 5</merge>
<merge key=”input.x11_options.XAxisMapping” type=”string”>6 7</merge>
<merge key=”input.x11_options.Emulate3Buttons” type=”string”>true</merge>
<merge key=”input.x11_options.EmulateWheelTimeout” type=”string”>200</merge>
</match>

Problem fixed!

I’m not sure if I also need the “Y” axis line in the file also (or the “X” asix line for that matter), but everything seems to be working as expected.  On top of this, Firefox was also working exactly as expected with horizontal and vertical trackpoint scrolling working (without any changes on the about:config page).

Counting occurrence of a particular word in Vim

Wednesday, January 28th, 2009

There is no built in word count feature in Vim, but a simple use of the substitute command can be used for the same purpose.

:%s/word//gn

Vim returns something along the lines of:

14 matches on 47 lines

Basically we are performing a search and replace but telling Vim not to take any action. If we break down the command we can see how it works.

:s – is the substitute command (find and replace)

% – putting the ‘%’ in front tells Vim to substitute across the whole file (not just this line)

<word> – this is the word we are counting (it could also be a regex expression, see below)

g – the ‘g’ switch tells Vim to search the whole line (globally) and not stop after the first match

n – the ‘n’ switch tells Vim to take ‘N’o action. This is what we want as we are only counting.

Using  regex:

Usually this command counts all occurrences of the word, but we can make it more useful with a sprinkling of regex. Say you want to count all lines that begin with comments (shell style):

:%s/^#//gn

Or all lines that are empty or only contain whitespace:

:%s/^\s*$//gn

The source of this tip is from the tips built into the Vim online help. If you enter the following command, you will get the help page version of what I have documented here (took me a while to track this down inside Vim).

:h count-items

Using Vi commands to control your shell (ksh, Bash)

Saturday, September 13th, 2008

Recently I was forced to use the Korn Shell (or ksh) when I had to perform some minor tasks on an AIX server. So of course I just jumped in and started using the shell. A few seconds later I was thoroughly frustrated as I discovered I had no command history and couldn’t use backspace or command completion (as you can probably guess I’m a Bash user).

The Vi mindset

So begrudgingly I resorted to a few web pages to work out what was going on. To my pleasant surprise, all I had to do was switch my thinking from Bash to Vi. I’m a big Vi(m) fan and feel quite at home using Vi like commands so I was quite happy to discover this was all I had to do. Command history: just hit ESC and use the Vi “up” which is “k” to go back in history, or Vi “down” which is “j” to go forward in history – easy.

Keeping in this mindset I began investigating other commands. Jumping back in history, then a quick “cw” to change a word, “A” to append to the end of that command. I wont bore all the people that don’t use Vi(m) with a list of commands, because if you don’t, then all this probably sounds like a pretty painful way of using a shell. But if you do use Vi(m) regularly, you quickly learn that a few carefully selected keystrokes can save you many repetitive backspaces or left arrows etc.

Escape from home

The other great thing about using Vi(m), or a Vi like interface, is that your fingers never need to leave the home keys. The only exception to this is that pesky ESC key that has been banished to the far corner of the keyboard. But never fear, there are some fixes to this.

The answer is to remap your CapsLock key to be another Ctrl key. Not only does this open up a wealth of shortcuts that can be performed without taking you fingers away from the home keys, but it also allows you to type an ESC equivalent, which is Ctrl-[.

If you are running X11 you can do it in the (re)configuration. Running Gnome you can do it through keyboard preferences, I’m guessing there is something similar in KDE and other window managers. You can even do it in Windows with a simple registry hack.

More information for Linux, Mac and Windows at the below links:

http://www.manicai.net/comp/swap-caps-ctrl.html

http://johnhaller.com/jh/useful_stuff/disable_caps_lock/

Dessert time

Anyway, whilst I was pretty impressed with the interface that ksh had on offer (once I understood it), I wasn’t totally sold. Command line completion was there (ESC+\) but it was nowhere near the level of Bash’s usefulness.

But…..inspired by this discovery, it didn’t take long to work out that I could have my cake and eat it too! A simple command in Bash allows these Vi like commands to be used:

set -o vi

This way you can keep on using Bash as you would, but hit the ESC key (or Ctrl-[) and you have the power of Vi at your fingertips!