## Tuesday, September 20, 2011

I'm running Ubuntu 11.04. When I change the configuration of xinetd, I have to use
sudo service xinetd reload
rather than
sudo service xinetd restart
Specifically, when I add a custom service to /etc/service and I do "restart", xinetd does not pick up the config changes.

I was getting this error in /var/log/syslog
service/protocol combination not in /etc/services: my-custom-service/tcp
so I added this to /etc/services
# Local servicesmy-custom-service          13082/tcp
In this circumstance, "restart" did not make xinetd re-read the config files and change its behavior. However, "reload" did.

## Friday, May 13, 2011

### Fabric and Pageant

Here's an example of using Fabric with Pageant, the ssh key agent that comes with PuTTY.

We're using ssh keys in PuTTY (.ppk) format, not in OpenSSH format.

It's a long example, but the work of connecting to Pageant happens in the _start_pageant_and_store_key function.

# Regular Python imports## Note: In the fabfile, don't do regular python imports like this##from urllib import urlopen## rather do them like this##import urllib## Any functions imported into this fabfile will be regarded as possible fabric# tasks (in the example above, urlopen will show up when the user runs 'fab# --list'), so instead of importing specific functions from modules, just import# the whole module.# http://docs.fabfile.org/en/1.0.1/usage/execution.html#importsimport os.pathimport subprocess# Import Fabricfrom fabric.api import envfrom fabric.api import runfrom fabric.api import sudo# To run the tasks defined in this file, use the 'fab' command line tool.# cd \path\to\fabfile.py# fab dev|prod task1 [task2]## Note that you must specify dev or prod first, to set up the right server# connection configuration.# ConstantsKEY_DIR = r'\path\to\keys'PUTTY_DIR = r'C:\Program Files\PuTTY'# These functions become tasks that can be executed from the command line using# the 'fab' tool.# Note: I couldn't find a more elegant way of specifying different connection# parameters (such as key_filename) for each host, so I just made a 'dev' task# and a 'prod' task.def dev():    """    Set up for connection to the dev server    """    # Once DNS is set up for these hosts, I can use hostname instead of ip address    env.user = 'admin_user'    env.hosts = ['dev_server']    _start_pageant_and_store_key('key2.ppk')def prod():    """    Set up for connection to the prod server    """    env.user = 'admin_user'    env.hosts = ['prod_server']    _start_pageant_and_store_key('key1.ppk')def install_all_all():    """    Install everything to all servers    """    dev()    install_all_dev()    prod()    install_all_prod()def install_all():    """    Does all the installation.    """    ps()    add_group('admins')    # Note: put actual installation steps here.# These utility functions are the building blocks of the install process. The# can also be called individually on the command line, using the 'fab' tool, and# specifying the target host and values for the arguments.def ps():    """    Prints a process listing    """    run('ps -ef')def add_group(group_name):    """    Adds a linux user group.    """    # --force  This option causes the command to simply exit with success    # status if the specified group already exists.    return sudo('groupadd --force %s' % group_name)# These private python functions do not get exposed on the command line via the# 'fab' tool. They will not show up when the user runs 'fab --list'def _start_pageant_and_store_key(keyfile_name):    """    Starts the Pageant key agent, and loads the private key in to it, prompting    for the passphrase if needed. Also sets the Fabric env.keyfile_name    property.    """    keyfile_path = os.path.join(KEY_DIR, keyfile_name)    # Start pageant. Note that this works with the PuTTY key format (*.ppk), not    # the OpenSSH format.    path_to_pageant = os.path.join(PUTTY_DIR, 'pageant.exe')    result = subprocess.call([path_to_pageant, keyfile_path])    if result > 0:        raise OSError, "Bad result %s" % result    # Store the path to the key file in fabric's global env dictionary    env.key_filename = keyfile_path

Thanks to Luka Marinko for his instructions for setting up syntax highlighting on Blogger.

## Wednesday, May 11, 2011

### Bash history

Use Ctrl-R to perform an incremental search on bash history. Press Ctrl-R again repeatedly to scroll backwards through matching commands.

http://www.tahttp://www.blogger.com/img/blank.giflug.org/events/20030709/cmdline_history.html
http://superuser.com/questions/7414/how-can-i-search-the-bash-history-and-rerun-a-command

## Monday, May 9, 2011

### Line continuations and && in DOS

Notes to myself:

• && works in DOS too (only do step 2 if step 1 succeeded)

• Use ^ for line continuation

• Use %ERRORLEVEL%, labels, and goto, for some primitive flow control.

Here's an example

@echo offset basedir=Z:\path\to\dircd %basedir% && ^hg fetch -R .\MRA && ^hg fetch -R ".\Super common" && ^hg fetch -R .\ServerKpfgoto answer%ERRORLEVEL%:answer0echo hg fetch completekomodo "%basedir%\ServerKpf\dev_util_nds_dev.kpf"goto end:answer1echo Program had return code 1pausegoto end:end

References
Multiple Commands in Single Line
DOS IF command

## Thursday, February 17, 2011

### February 17

I just got back from a rally on the steps of the Winnebago County Courthouse, organized by Rep. Gordon Hintz of Oshkosh. The rally was to protest Scott Walker's proposal to eliminate collective bargaining for state workers. Main theme: It's not about the money, it's about the disrespect Walker shows all working people when he takes away their right to have a say in their working conditions.

There's another rally in support of state workers ** 5PM Today (Thursday 2/17)** in Opera House Square, downtown Oshkosh.

## Sunday, February 6, 2011

### SSD Saga continued

So I got my OCZ Vertex2 SSD some time ago, and I managed to get it running in AHCI mode on my existing Windows XP pc. However, I had not yet transferred my windows system partition from hdd to ssd. A good job for Super Bowl Sunday, as it mirrored the highs and lows, the moments of elation and crushing despair, that I would have experienced had I watched the game itself.

After many false starts, I arrived at this process:

1) I aligned the partition, and formatted the whole ssd drive as one partition.

2) I used Clonezilla to copy my C: drive partition on my hdd to the new empty partition on the ssd. I used the "device-device" (device to device) menu option, with the basic (not advanced) option.

So far, so good. Here's where the fun began. Naturally, after such a cloning operation (operating on partitions, not the whole disk), the master boot record on the SSD was not set up properly to boot into windows.

First, I unplugged the hdd, so the ssd would show up as C: (and so I wouldn't fat-finger it into oblivion). I booted from the XP install disk into the Recovery Console, and used the three classic incantations:
fixmbrfixboot C:bootcfg /rebuild
This is supposed to repair the mbr, and make the drive bootable. No dice. I just received the message "Error loading operating system" on a black screen.

I turned to the old reliable, Ultimate Boot Cd (not UBCD4win this time)

It comes with several MBR tools. The one that worked for me was MBRWork (version 1.07b)

Here's how to use MBRWork, from here and here
Steps to recover lost partitions
7> Change active hard drive. (ignore if you have only one hard drive)

1> Backup first track

4> Reset MBR to zero

3> Reset EMBR area to zero.

A> Recover MS Partitions (see fig 2)

5> Install standard MBR code

Reinstall your boot manager. (if used)

See explanations below..

Below view shows after 4> Reset MBR to zero. A> Recover MS Partitions has been
added to the list of options, also notice MBR Partition Information is
now all zeros. There are no longer any partition boundaries, meaning the hard
drive is unbootable and you can't read any data. If you now try to use fdisk
or other utility to recreate the partitions, new file tables will mean all
your data will be inaccessible, except for data rescue efforts. MBRWork finds
the original partition boundaries and reconstructs them exactly as they were,
meaning your computer works again and the data is intact.

1) Backup First Track This is your safety valve to put things back as they were
2) Restore First Track Appears as an option only after using 1)
3) Reset EMBR Clear extended partition area
4) Reset MBR Remove partitions
5) Install Std MBR Same as fdisk /mbr (removes any boot manager)
6) Set active partition Also can be done with fdisk
7) Change active HD
8) Only shows if DDO present Remove Dynamic Disk Overlay (i.e. EZDrive, Maxblast)
9) Capability Check Runs tests on your BIOS, makes no changes.
E) Exit
A) Recover partitions Appears only after running 3) (and/or 4)

Success! It boots, and is much much faster booting and loading programs. And, it's still aligned properly, according to this ssd alignment calculator.

However, if you're using XP, and thinking about transferring your existing install to an ssd, know that it is not an easy or straightforward operation. Newer versions of windows are apparently much smarter about the way they handle ssds.

## Tuesday, January 18, 2011

### Using the GNU tools for find and replace on Windows

There are many ways to do find and replace in multiple files on Windows. I use the familiar GNU find | grep | sed tools.

I use the GnuWin32 version of the unix utilities. I have used UnixUtils, but they are now outdated. The Automated gnuwin32 download tool downloads and manages the gnuwin32 utilities. Read the Readme in the getgnuwin32 distribution folder for instructions.

The use of GNU utilities in the windows command prompt environment is not without pitfalls. You use only double-quotes. There are problems with filenames containing spaces, and with path separators. We handle dodgy file names the same way we do on Linux, by passing around null-delimited lists of file names.

In this example, I'm replacing the &frasl; html character entity with the more common slash &#47;. I have broken it down in to smaller steps, and I save the intermediate results to temp files.

First I find all the html files. I put all the file names in to a temp file. Passing -print0 separates the file names with null strings.
find "C:\The\windows\path to\my directory" -name "*.html" -type f -print0 > "C:\Temp\tmp.txt"

Next, I use xargs to read in all those null-delimited file names, and run grep over them looking for the &frasl; html character entity. I write out the names of files where grep found &frasl;
xargs --null --arg-file="C:\Temp\tmp.txt" grep --null -l "&frasl;" > "C:\Temp\tmp2.txt"

Then, I use sed to replace all instances of &frasl; with &#47;. Note that I have to eascape the & in the replacement.
xargs --null --arg-file="C:\Temp\tmp2.txt" sed -i -e"s/&frasl;/\&#47;/g"

Now I check the results. This grep should now find nothing.
xargs --null --arg-file="C:\Temp\tmp.txt" grep "&frasl;"