29 March 2008

netca and /etc/hosts

When I first re-installed my laptop with Fedora 8, I naturally set about installing Oracle 10g. However at the end of the dbca process, the launching of netca failed. Trying to run netca manually yielded this fun error:

[oracle ~]$ netca

Oracle Net Services Configuration:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  SIGSEGV (0xb) at pc=0x004f0ab3, pid=19917, tid=3086797008
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_14-b05 mixed mode)
# Problematic frame:
# C  [libc.so.6+0x6fab3]  index+0x63
#
# An error report file with more information is saved as hs_err_pid19917.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#
/u01/app/oracle/product/10.2.0/db_1/bin/netca: line 190: 19917 Aborted
$JRE -mx64m $SRVM_PROPERTY_DEFS -Dsun.java2d.font.DisableAlgorithmicStyles=true -classpath $CLASSPATH oracle.net.ca.NetCA $*

Well that was no good. I saw some threads with similar subject matter on the OTN forums and followed up. However time passed and then for seemingly no reason at all the next week, netca was working fine. Then a kind gentleman replied asking what my hostname was set to. BAM!

That's when it dawned on me that the hostname that I had set for this laptop was not in any DNS service available at the time. It was set up in my office in Green Bay, but I wasn't connected to that in Schaumburg. From home last night I disconnected from the VPN and removed my localhost entry for my hostname. Bingo, netca fails. Re-add the localhost entry, netca works.

I had originally added my hostname to the localhost line in /etc/hosts because gnome-terminal would take forever and day launching without DNS resolution of the hostname, waiting for the lookup to timeout. Apparently this same kind of thing is going on just to launch netca, although it just crashes.

Here is the entry in my /etc/hosts, for example:
127.0.0.1    localhost.localdomain   localhost       foo.example.com foo

26 March 2008

Moto RAZR + Bluetooth + Linux + Python = ObexCopier

While in Schaumburg, Illinois last week for the Oracle DBA Workshop II, I was taking some photos on my Motorola RAZR camera phone, in the hopes of posting them for my 5-year-old daughter to see. I needed to clear up some misconceptions, since she was under the impression that I "sleep at the school." I soon learned, however, that transferring photos from the RAZR one-at-a-time over bluetooth to my Fedora 8 laptop became tedious, and waiting for a response from the GUI file browser was just frustrating. Enter: ObexFTP.

Thanks to a tip from a friend, I found ObexFTP and, in my quest to force myself to learn python, set about crafting a script to do the following:
  • Transfer files based on a date (default to today).
  • Transfer all files in the directory.
So I'm presenting to you my first stab at it. Some of the hard-codings depend on how the RAZR stores photos in the micro-SD card. If anyone wants to submit enhancements or critiques, I'm all ears. Right now it just works for what I needed it to do.

#!/usr/bin/env python


# Don Seiler, don@seiler.us


import obexftp, ConfigParser, os
from xml.etree.ElementTree import XML
from optparse import OptionParser
from datetime import date


# This script is dependent on the Moto Razr convention of naming
# pictures in an MM-DD-YYYY_XXXX.jpg format


# Users need to create ~/.obexcopier.ini with these variables defined
# [ObexCopier]
# device = 1A:2B:3C:4D:5E:6F
# channel = 6
# source_dir = /MMC(Removable)/motorola/shared/picture
# dest_dir = /media/pictures


# Read config from ~/.obexcopier.ini
config = ConfigParser.ConfigParser()
config.read(os.path.expanduser('~/.obexcopier.ini'))


# Probably a waste of precious memory to store these again
device = config.get('ObexCopier','device')
channel = config.getint('ObexCopier','channel')
source_dir = config.get('ObexCopier','source_dir')
dest_dir = config.get('ObexCopier','dest_dir')


# Get today for default date
today = date.today().strftime("%m-%d-%y")


# Command-line handling to allow for date
parser = OptionParser()
parser.add_option("-d", "--date", dest="date", default=today, help="Grab pictures from this date, defaults to today [default: %default]",metavar="MM-DD-YY")
parser.add_option("-a", "--all", action="store_true", dest="all", default=False, help="Copy all files, regardless of date [default: %default]")
(options, args) = parser.parse_args()


# Connect to the client
print "Connecting to %s on channel %d" % (device, channel)
cli = obexftp.client(obexftp.BLUETOOTH)
cli.connect(device, channel)


# Get the list of files from the SD card picture dir
if options.all:
print "Copying all files to disk"
else:
print "Copying files from %s" % options.date


files_xml = cli.list(source_dir)
folder_listing = XML(files_xml)
files = folder_listing.findall('./file/')
for file in files:
# Only handle pictures taken on the specified date
if options.all or file.get('name').startswith(options.date):
print "Copying %s" % file.get('name')
data = cli.get(source_dir + '/' + file.get('name'))
localfile = open(dest_dir + '/' + file.get('name'), 'wb')
localfile.write(data)
localfile.close()


# Disconnect and delete the client
cli.disconnect()
cli.delete