Thursday, June 30, 2005

Offline NT Password & Registry Editor

This is an incredibly useful tool:
http://home.eunet.no/~pnordahl/ntpasswd/

It saved me when I corrupted the MBR on my work laptop's hard drive,
and didn't have the Administrator account's password (required by
default to enter the Windows XP Recovery Console).

It's a very small/minimal linux kernel, with a few powerful tools.
You can download and create a boot floppy or boot CD, and when you
boot from it, you can change your Administrator password, or even edit
your registry!

Thursday, June 09, 2005

misc notes on my recent experience with parallelknoppix, clusterknoppix, and fedora

This is far from complete, and could use a lot of detail such as links
to the web sites I mention in here, etc. Maybe I'll update it later
with that information.

- can't write to NTFS in Parallel Knoppix
- openmosix terminal server lets slave nodes boot from image stored on
master HD, but that requires:
- slave notes have network boot capability (PXE)
- may require BIOS flash upgrade
- may need to change options in BIOS setup
- enable network boot/PXE option
- change boot order to try network first
- master needs to load drivers for relevant NICs on slaves
- sometimes challenging to find which driver
- pcimodules
- dmesg
- lspci -v
- creative google searching
- drivers in other OSes on that machine may provide clues
as to exactly which model number/chipset/etc. a NIC is, so you can
then google those numbers in search of info on which driver to use in
knoppix.. check hardware properties in windows device manager, etc.,
and look at driver versions/details.
- checking all drivers in list requires much more disk space on master
- GUI driver checkbox list very slow
- i liked to just edit the terminal server startup script,
modifying the regular expression that checks certain checkboxes on the
list by default. but that was probably more trouble than it was worth
to try and tell someone else to do.
- if BIOS doesn't support PXE, download driver in a boot disk
image from the etherboot project, at http://rom-o-matic.net, then
write that image to a floppy with RAWRITE tool, and boot a slave from
that floppy.
- need to copy cd image to master HD for slaves to remote-mount
- plug master and slaves into one hub/switch, isolated from internet,
etc, and disable any network hardware that is not relevant. this may
not be required, but it simplifies things, so it's more likely to
work.
- couldn't get parallelknoppix to use my USB HD with FAT partition for
permanent storage for the terminal server. could use the drive
normally in parallelknoppix, but not for the main purpose i needed
non-NTFS storage for.
- machines with too little memory couldn't have a large enough ram
disk, so they didn't want to be master

- tried in vain to get clusterknoppix or parallelknoppix working on my
network at home, attempting with 6 different machines, in various
combinations, spending a total of probably 40 hours on this task. it
pains me to say that I never did get a useful cluster working at home.
luckily, our group was able to get one working between our 4 laptops,
in a matter of only about 4 hours, including recording a 30 minute
video of the process after somewhat perfecting it.

- when a master's terminal server is running and slaves are connected,
they mount a directory on the master, and they are able to read/write
files anywhere in that directory tree. supposedly this is not
designed to be secure, it's designed to be quick and easy and used in
environments that are as secure as they need to be.

- ClusterKnoppix
- hardware support nicer for me (such as mouse buttons)
- includes CaptiveNTFS for mounting NTFS partitions read/write
instead of read-only
- openmosix viewer seemed to automatically see other
ClusterKnoppix machines on the LAN, and automatically clustered them
and showed their processor usage in the one viewer window, but that
only worked for me two weeks ago. last week when I tried again, I
couldn't get any 2 machines in my house to recognize each other as
nodes to cluster.

- challenges I encountered with Fedora:
- tried to install fedora on several machines, but the only
install that really worked out well was on a machine that I dedicated
to fedora.
- I let fedora start with an empty hard disk and partition it
automatically, etc. that machine worked out fine, and that's what I
ended up doing my individual assignment on.
- was able to easily:
- use sendmail for local email
- create samba shares that my windows machines could mount
- read ntfs, and write ntfs as well after i played
with the mount command/options
- set up web server, vnc server, etc
- one machine took 7 hours to install from the 4 fedora CDs.
painful. then, it was not even able to start up after the install.
kept hanging during the fedora startup sequence.
- another machine had the same kind of hanging issue, but did
not take nearly as long to install initially.
- tried obsessively to get fedora to install and boot off of
an external USB hard drive.
- various discussion threads can be found by googling
which explain step-by-step how people have accomplished this.
- it was not simple/straightforward whatsoever, and I
never did get it to work, after spending probably 20+ hours on it over
the course of several days.
- getting it to install on the usb drive was the easy
part. getting it to boot from it was not.
- the main reason for trying to do this was because most
of my machines only have NTFS partitions, and fedora wasn't crazy
about that fact. so I wanted to be able to install it on FAT or ext3
partitions on the external HD, so I could avoid messing with my work
laptop's hard drive and stuff.
- managed to corrupt the MBR on my work laptop in the process
- found useful NT admin password resetter tool, which
allowed me to then boot from the windows XP setup CD and go into the
Recovery Console, where the FIXMBR command saved me.
- two other machines at home were disqualified by the fact
that they only had NTFS partitions.

Friday, June 03, 2005

miscellaneous search/replace regular expressions I've used recently in TextPad

Here are some miscellaneous search/replace regular expressions I've used recently, that seemed worth keeping (to me). I used these in TextPad with the option in Configure Preferences Editor, called "Use POSIX regular expression syntax", checked. Sometimes I find that TextPad's search/replace functionality is more useful to for a particular purpose than 'sed' in unix/cygwin. Other times I use sed and stuff. That's the beauty if cygwin, I can mix and match windows and unix whenever I want (as some previous and near future posts will show).

These are mostly presented in the format:
Line 1: short description of search/replace expressions
Line 2: regex to search for
Line 3: replacement expression

change from (myMaybeNullFunc().equals("myStaticString") to ("myStaticString".equals(myMaybeNullFunc())
([\(]*)([a-zA-Z\.\(\)]+).equals\("([^"]+)"\)
\1"\3".equals(\2)

change from (myMaybeNullVar.equals("myStaticString") to ("myStaticString".equals(myMaybeNullVar)
([^a-zA-Z])([a-zA-Z]+).equals\("([^"]+)"\)
\1"\3".equals(\2)

change from myResultSet.getString("foo") to myObject.getFoo()
myResultSet\.get[A-Z][a-z]+\("([^_"])([^_"]+)"\)
myObject.get\u\1\2()

change from myResultSet.getString("foo_bar") to myResultSet.getString("FooBar")
rs\.get([A-Z][a-z]+)\("([^_"])([^_"]*)_([^_"])
rs.get\1 ("\u\2\3\u\4

(run this one repeatedly until no more matches, then run the one above it)

change HTML start tags to upper case
<(\<[[:word:]]*\>)
<\U\1

change HTML end tags to upper case
</(\<[[:word:]]*\>)
</\U\1

TextPad 'tool' definition to open generated .java file based on currently open .jsp file

Set this up as a Tool in TextPad, and dropped the sed script (at the bottom of this post) into my cygwin home directory's bin directory (~/bin/), and now I easily open the .java file that tomcat generated when it last compiled the .jsp that I'm currently editing. This is helpful for debugging sometimes, when the compilation error message does not include the .jsp file line number, just the .java file line number.

Command:
c:\cygwin\bin\bash.exe

Parameters:
-c "'/cygdrive/c/Program Files/TextPad 4/textpad' \
`echo '$File' sed -f ~/bin/GeneratedJava.sed`"

Initial Folder:
c:\

Checked options:
Run minimized
Close DOS window on exit


~/bin/GeneratedJava.sed contents:
#!/usr/bin/sed -nf

s/path\\to\\my\\jsps/apache\\tomcat5\
\\work\\Catalina\\localhost\\mywebappname\
\\org\\apache\\jsp/

s/\.jsp/_jsp.java/

sorted list of number of changed lines in files that need to be checked into cvs

Sometimes I make one change to a set of files, sometimes even a large set of files. Say, for instance, that I changed which java package a class resides in. Then, I'd probably run a set of commands that would search and replace the import statements in all files that use that class. But, at that point I might now have 20 files in my source tree that need to be checked in, which all have the exact same change, to just one line in each file.

If my local source tree was up to date with CVS before that, the checkin would be easy. I could just cvs commit at the root of the tree, and enter one comment ("changed package of class X from a.b.c to a.d") to describe the change to all of them.

But, usually I've got at least a couple other things that need to be checked in, so I have to either go through all of the files, one at a time, or do something automated. The following is one set of commands that has proven useful to me for this purpose. I've got another, but it's not quite ready to share (that will come soon).

The commandline below will safely and quietly cvs update to get a list of modified files (marked with an "M"), then run cvs diff on each file and count the lines in the diff output.. then they are all sorted numerically by number of changed lines, and displayed. I can easily see that all of the files with 5? (i forget exactly.. however many lines show up in a 'cvs diff' for a single changed line in a source file) changed lines, and can probably check them all in with one comment.

(for f in `cvs -q -n update grep '^M' sed -e 's/^M //g'`; do echo `(cvs diff $f wc -l)` $f; done) sort -n

Sybase ASE 12.5 error message about 'select into' option needing to be enabled

Sybase (ASE 12.5) error message I was getting when trying to modify a column's metadata/attributes:
   The 'select into' database option is not enabled for database 'myDbName'. ALTER TABLE with data copy cannot be done.
   Set the 'select into' database option and re-run.
 
Solution that worked for me (including the column-altering command in the middle):

USE master;
EXEC sp_dboption "myDbName","select into/bulkcopy",true;
COMMIT;
USE myDbName;
ALTER TABLE myTableName
MODIFY myColumnName varchar(60) NOT NULL;
USE master;
EXEC sp_dboption "myDbName","select into/bulkcopy",false;
COMMIT;

References:
Ed Barlow's "fix_db.pl" script, which I happened to find the solution in when grepping my local machine.
http://www.edbarlow.com/document/utilities/readme.htm

This page, where I stumbled across the solution eventually, as one of many google search results.  I had result pages open in several windows, and was looking through them when I noticed the grep results.
http://www.devx.com/vb2themax/Tip/18583