Friday, December 12, 2008

Trapping in bash

Scenario: You are running a code deployment to a small server farm of maybe 10-15 servers. Too small for something like tentakal, but too big to just ssh and deploy, logout, wash - rinse - repeat.

So you write a simple while; do loop and roll your stuff out that way.

The problem comes up when you realize that the deployment is hanging on a particular function, and you want to exit from that session, but want to continue your deployment on the rest of the machines - or whatever...

Enter my friend "trap".

Trap can pick up a variety of signals, and act on those in whatever way you wish.

Example: You want to stop someone from hitting ^C:

#!/bin/bash

trap "echo 'tsk tsk - no ^cing!'" 2
while true; do
echo "I dare you to press ^C"
echo ""
sleep 15
done

So - this will wait for the signal 2 (INTerrupt), and print tsk tsk - no ^cing! to the screen everytime you hit ^C.

Now, how do you stick this into a script so that it will execute that portion until it gets a ^C?

#!/bin/bash

# some code.. do what you want here...

#Trap code:

# First trap - if ctl-c is hit, it will go to the next function:
while [ trap -ne 2 ] ; do
# your commandline/script code here
done


# The next function:

while [ trap -ne 2 ] ; do
# your commandline/script code here
done

...and so on...

Thursday, December 4, 2008

PCLinuxOS on the Dell Inspiron 1526

The Dell Inspiron 1526 was too inexpensive for the power to pass up.. but I did not want to run Windows on it, and I didn't want to run Ubuntu (nothing against it, just not my cup of tea). I also didn't want to force my favorite linux (Slackware) to work on it, since this was to be used for everyday work.

PCLinuxOS seemed to offer exactly what I wanted.

I installed it and it just worked. That is, except the wireless. If there was anything that I would have be an issue, it is the wireless - since there are so many ways to hack that to work.

Step-by-Step (as root, to avoid having to sudo every time):

1) echo -e 'blacklist bcm43xx\nblacklist wl' | sudo tee -a /etc/modprobe.d/blacklist

2) wget ftp://ftp.us.dell.com/network/R174291.exe

3) mkdir bcm-drivers

4) cd bcm-drivers

5) unzip ../R174291.exe

6) ndiswrapper -i bcmwl5.inf

7) depmod -a

8) modprobe ndiswrapper

9) echo 'ndiswrapper' | sudo tee -a /etc/module

10) Click Control Center -> Network -> Set up a new network interface -> Wireless

11) Follow the prompts, and use the Broadcom driver that now shows up (or should)

12) You should be taken through the process of configuring the wireless network.

13) In your terminal window, as root, type: ndiswrapper -ma

14) in your terminal window, open /etc/rc.d/rc.local and add:

depmod -a
modprobe ndiswrapper
ndiswrapper -ma

15) All done. Now when you reboot, your wireless interface will be there.