Posts Tagged ‘UNIX’

vim tips: deleting lines matching regex

Friday, January 11th, 2008

In vim you can use :global to perform actions based on regular expressions.

Thanks to MichaelRaskin1 in #vim on Freenode I can now remove lines that don’t match what I’m looking for in a file.

To try it out, let’s have a testcase.  You have some truss or strace output you’re looking through and want to see all of the open() calls (without dropping to a shell and running grep); try this:

:%g!/^open/del

This is pretty straightforward: delete (del) all lines (%g) that do not (!) start with (^) open.

Boosh.  Thanks Michael.

vpnc-script issues with ash shell

Tuesday, June 26th, 2007

Today I decided to set up vpnc on my Linksys WRT54G router. I want to be able to connect to the VPN at work, and the Linksys is an ideal place to do it.

The setup I’m aiming for (where a single port gets VLANd off and becomes the only available to connect to the inside of the VPN at work) is trivial to do and I’m 98% sure one of the guys at work has already done it (although probably with some slightly different software, I’m not sure).

I run OpenWRT WHITE RUSSIAN 0.9 on my Linksys, which was the latest at the time I installed it. I believe there is a new development release, but this still seems to be quite current.

First step was getting vpnc installed with the necessary bits and pieces. OpenWRT comes equipped with what can only be described as a very streamlined version of apt: ipkg. I searched for vpnc over at www.ipkg.be, found a hit and as such added the necessary line to my /etc/ipkg.conf file. A quick update and I could install vpnc, kmod-tun and libgcrypt as required.

With my VPN config file in place, I quickly received an error:

/etc/vpnc/vpnc-script: 222: Syntax error: Bad for loop variable

What’s on line 222?
for ((i = 0 ; i < CISCO_SPLIT_INC ; i++ )) ; do

I did some searching and it seems this is perfectly valid Bourne syntax, so what gives? Well, OpenWRT uses ash as the default shell, not bash or sh. I decided to replace it with something equivalent:
i = 0;
while [ "$i" -lt CISCO_SPLIT_INC ]; do
// there was some stuff here, I added the next line just before the "done"
i = `expr $i + 1`

I had to make this fix a little further down too, but this did the trick and vpnc now correctly adds all of the default routes and properly updates the /etc/resolv.conf.

Linux Skype 1.4 BETA supports SMS (and other new features)

Sunday, June 17th, 2007

I’ve been using the new Skype 1.4 BETA for the last day or two.  It works quite well and the user interface has been massively updated.

In addition, I just discovered that this 1.4 BETA implements the full Skype API, which means that we already have the ability to send SMS messages with Linux Skype.

Currently the GUI does not provide all of the necessary hooks, but by following the simple steps described at share.skype.com/sites/devzone/2007/05/skype_api_is_catching_up_on_li.html I was easily able to send a quick test SMS to my mobile.

It won’t be long before Skype release an updated GUI, I hope.  But if not, no worries… I can write one myself.

Getting a Sun Ray DTU MAC address

Friday, June 15th, 2007

Handy little script to output the MAC address of your Sun Ray DTU. Based on Chris Gerhard’s Sun Ray firmware version blog post from a week or two ago:

$ /opt/SUNWut/bin/utwho -c | nawk '$3 == ENVIRON["LOGNAME"] {print substr($5,4)}'
0003ba4ea9dd

Love your $ENVIRONMENT

Tuesday, April 17th, 2007

This evening I set up a simple Subversion repository to host some web content over on noisy at CompSoc.

Everything was up and running and Vlad and I were able to successfully checkout, update and commit changes to the Apache/mod_dav_svn repository. Permissions were configured in a sensible way. /home/lewiz/svn belongs to lewiz:www and is chmod 0770. Apache runs as the www user and this way I had total control over all of the files, while still allowing Apache to do the necessary goodness.

I came across an interesting FAQ in the Subversion docs that concerned me. As we are both doing web development and work in a standard change-commit-fix cycle it makes sense for the actual copy of the site to be always updated. I wanted to run an update every time a change was committed.

http://subversion.tigris.org/faq.html#website-auto-update covers this perfectly and makes use of the post-commit hook by way of a simple C programme. Everything seemed set but on my initial commit with the post-commit hook in place I saw:

$ svn commit
Sending index.php
Transmitting file data .
Committed revision 6.

Warning: ‘post-commit’ hook failed with error output:
Error validating server certificate for ‘https://www.compsoc.man.ac.uk:443’: – The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
Certificate information: – Hostname: www.compsoc.man.ac.uk – Valid: from Sun, 21 Jan 2007 15:34:35 GMT until Mon, 21 Jan 2008 15:34:35 GMT – Issuer: The University of Manchester Computer Society, Manchester, UK – Fingerprint: 39:2a:09:a1:d1:d1:4f:f6:44:fd:6b:1b:ad:c6:f4:55:29:e8:2e:07
(R)eject, accept (t)emporarily or accept (p)ermanently? svn: PROPFIND request failed on ’/svn/lewiz/walktojapan/testsite’
svn: PROPFIND of ’/svn/lewiz/walktojapan/testsite’: Server certificate verification failed: issuer is not trusted (www.compsoc.man.ac.uk)


Ouch! This really isn’t good. I initially assumed that the script was not running as me so I double-checked the setuid bit and so on. Once this was confirmed I realised that svn simply didn’t know where to find my hashed password and certificates.

Some man pages and a Google later and we come across the true goodness of execle(3).

execle() allows a pointer to a null-terminated list of environment variables to be passed to the binary being exec()d. In my case the script now reads:

char *env[] = { “HOME=/home/lewiz”, NULL };
execle(”/usr/local/bin/svn”, “svn”, “update”, ”/tmp/myrepo”, NULL, env);

Basic, maybe… but still new to me!

Here a core, there a core, everywhere a core-core!

Wednesday, April 4th, 2007

Over at CompSoc (where this blog is hosted) we’ve had some issues with PHP for some time now.

PHP executes code as it should, but as it exits it was dumping core on signal 11.

I’ve probed this once before and spotted that the backtrace pointed fingers at the session module.

I decided to have another look at this today and, armed with the knowledge that PHP was dumping core unloading session.so, I did some searching.

It turns out that simply moving extension=session.so to the top of extensions.ini provides a fix.

I have to say I’m most unimpressed with that.

Evince? Or Acroread?

Tuesday, April 3rd, 2007

Of course it depends on what you’re doing…

but the answer is ultimately provided to us by the CIA at  www.lib.utexas.edu/maps/world_maps/world_physical_2006.pdf

Try it and tell me which is best.

bash tab completion

Friday, February 9th, 2007
echo "set match-hidden-files off" >> ~/.inputrc

Finally!

Why desktop Linux sucks

Friday, February 9th, 2007

Desktop Linux is well behind Windows.  There are the obvious reasons, such as ease of use, support, etc.  I’d counter all of these with the stability of Linux, the fact that on a GNOME desktop everything is already there, lack of viruses, etc.

However, for most people this isn’t the issue.  The main problem is application support.

What do we have to do for Adobe to notice us?  Photoshop CS2 currently sells for almost £500… I’d be very hard pushed to afford this, but I would pledge that cash in an instant if it would bring about a copy of CS3 for Linux, or Solaris, or FreeBSD.  I’m sure other people would do the same for other Adobe products.

These days hardware support is less of an issue.  For the most part we get by… nVidia are providing great drivers, ATi are still trying to get there, while many other hardware is catered for by the third party.  But lately this hasn’t quite been enough… I’m starting to feel the gap between myself and my Windows counterparts… where is my nVidia PureVideo H.264 and DVD decoding?  Where are all of the good options for my Sound Blaster Audigy 2 ZS?

I’ve already put down the money for both of these pieces of hardware.  Given that there are a lot of people now running Linux on their desktops, it would be really great for us to see this support.

In the near future I hope we’ll see a revision of Vmware Workstation that includes a feature akin to the Parallels Coherency that Mac users have had for a short while now… and I bet they’re just as fed up at the lack of advanced hardware support.  What’s the better that they will see it before we do?  Pretty high, is my guess, and I don’t think that they really have a much higher percentage of the desktop market.

Oh, well…

StorageTek L20 Library Admin Webpage

Saturday, January 27th, 2007

If your StorageTek L20/40/180/700 autochanger library is sat on a private network and you fancy prodding the web GUI (assuming you purchased the serial dongle upgrade), try something like:

ssh -L 1234:IP_ADDR:80 -L 5001:IP_ADDR:5001 -L 5002:IP_ADDR:5002 SSH-HOST

In this example IP_ADDR is the private IP address of the library, as it is reached by the ssh server you are tunnelling through, in this case SSH-HOST.

You can now access the library interface by navigating to http://localhost:1234/ in your browser.