Fast User Switching from the command line on a Mac

It seems that some IT departments like to lock out the fast user switching option on company laptops in a lot of companies at the moment. This became a problem for me as I have a local admin account on my work machine, and I have to switch to it whenever I want to install from a dmg file. This got me thinking, is there a command line argument or tool that I could run to do this? Sure enough there is. The only thing you need to look up is the UserId for the user that you want to switch to.

Continue reading Fast User Switching from the command line on a Mac

How to clear DNS cache on a mac running OSX

Clearing the cache on Mac’s seems to change with every other release these days. In all cases though you need to use Terminal, but not always the same command. Back in the 10.4 days you would use lookupd, then in 10.5 and 10.6 you would use dscacheutil, but now in 10.7 you need to now use a killall command.

Continue reading How to clear DNS cache on a mac running OSX

Happy 20th Birthday Vim

Today marks the 20th anniversary of Vim, one of the most powerful and versatile command line text editors around. I’ve been a happy Vim user since I was at Uni. It’s installed on almost all every server I’ve used, and can be customised with lots of little scripts making it as useful as any GUI editor.

Two decades of productivity: Vim’s 20th anniversary (ars technica)

Transparent SSH keys – ways in which they can be useful

I’m sure you’ve read time and time again that ssh keys without a passphrase are bad, and that they should never be created, because they create an easy attack onto your system should someone get hold of your ssh public and private key pair somehow. However I find them very useful when accessing the development boxes at work, and I’m sure that anyone else who has to connect to multiple development servers or any internal servers come to mention it will agree; one less password / passphrase saves so much time. Be it connecting to the server to find a file, or scp’ing a file somewhere, or to run some remote command.

Continue reading Transparent SSH keys – ways in which they can be useful

Using grep, awk and sed to list files containing a string

This week I was trying to locate which files in the codebase use a specific class method while debugging some code. This method however has been used a lot, when I say a lot I mean 10 to 20 times per file, and in lots of templates. This is mainly because it is a template helper to generate complex links within the page. Anyway, a simple use of grep wasn’t all that much help, so I refreshed my memory on how to use sed to make the output a little more readable.

Continue reading Using grep, awk and sed to list files containing a string

svn diff via vim

When I’m reviewing the changes I’ve made to an svn checkout I prefer to see the changes in colour. This would be very easy if I was someone that used a graphical editor, but I’m one of those people that prefer to use vim, or vi if I really have to. As a result I had to think of a way of changing svn diff into something that was easy to read. I found out that vim has a syntax highlight template for diff files, so it got me thinking. What about pushing the diff into a file and then viewing the file in vim.
Continue reading svn diff via vim

Magic 8-ball written in bash

Have you ever wanted a magic 8ball to use at work? A real one, even though nice to have on your desk, is not always practical. When I had a real one on my desk people were forever playing with it when they came to talk to me.

Making one is very simple. All you need is an array of values to use as responses, and a way to pick one of them at random. I could have written this in any number of languages, but this one is written in bash for simplicity.

Continue reading Magic 8-ball written in bash

Marking files so that the root user cannot change them

I was having a discussion with one of the SysAdmins at work yesterday and we were talking about a system we use called puppet. I wanted to know if there was a way of making changes to one of the files currently under the control of puppet for testing purposes without stopping the puppet daemon. He pointed me in the direction of of the chattr and lsattr binaries.

These binaries allow you to mark any file on the machine as immutable or list the immutable status. If a file becomes immutable it means that not even root can delete or modify the file unless it removes the immutable flag first.

Continue reading Marking files so that the root user cannot change them