Archive for October, 2009

How to: Create Windows 7 USB install media from Linux

There are two ways to get the Windows 7 DVD iso to a USB drive for installation, the hard way (also its done via windows only) or there is my way, which is also the easy way. All of these insctruction are assuming that you are doing this from a Linux machine.  Although the tools that we are using are cross platform, I just have never tried it from Windows.

Step 1: Make sure that you have a big enough USB drive, they are cheap and I have been using an 8GB.  Although I 4GB might work.

Step 2: First get a hold of the Windows 7 DVD by any means (purchase, download, steal etc)

Step 3: Format the USB drive with NTFS.  FAT32 might work, I am not sure. Open a linux console and su – to root or in Ubuntu type sudo bash and then the correct password

First we need to determine which drive is your USB drive with dmesg. This will give you lots of data but if you just plugged in you USB device then the last lines is all we need:

linux# dmesg
usb 2-1: new high speed USB device using ehci_hcd and address 6
usb 2-1: New USB device found, idVendor=0951, idProduct=1607
usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1: Product: DataTraveler 2.0
usb 2-1: Manufacturer: Kingston
usb 2-1: SerialNumber: 000FEAFB8E96A930C5A90096
usb 2-1: configuration #1 chosen from 1 choice
scsi9 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 6
usb-storage: waiting for device to settle before scanning
usb-storage: device scan complete
scsi 9:0:0:0: Direct-Access     Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 2
sd 9:0:0:0: [sdd] 15695872 512-byte hardware sectors: (8.03 GB/7.48 GiB)
sd 9:0:0:0: Attached scsi generic sg4 type 0
sd 9:0:0:0: [sdd] Write Protect is off
sd 9:0:0:0: [sdd] Mode Sense: 23 00 00 00
sd 9:0:0:0: [sdd] Assuming drive cache: write through
sd 9:0:0:0: [sdd] Assuming drive cache: write through
 sdd: sdd1
sd 9:0:0:0: [sdd] Attached SCSI removable disk
fuse init (API version 7.11)

As we can see my USB drive is sdd or /dev/sdd

Next we need format it via NTFS. This will ERASE all you the data on you USB drive. So make sure you have it backed up.

linux# mkfs.ntfs /dev/sdd1

This might take a while, so go get a drink.

Step 4: Next download Unetbootin.  Unetbootin is nice because for most Linux distros you don’t have to pre download the ISO image, Unetbootin will do that for you.  But in this case, because Windows 7 is not free, you have to the ISO.

Step 5: Once it is installed run it (If you need help installing it, the Unetbootin site has good instructions)

Check the Diskimage radio button and then click the browse button to select the Windows 7 ISO.  You will also have to check Show All Drives and then select the drive and partition of your USB device, in my case /dev/sdd1.  The /dev/sdd1 is relevant to my system, it may not be the same on your system.  Once you click OK the data on that partition will be removed so make sure that you are selecting the USB drive not your local hard drive.  I am not responsible for your mistakes!!!

unetbootin-win7

Once you click ok you will see a status screen showing you the files that are being copied to your USB drive.

Step 6: Once Unetbootin is finished we need to download and copy two files to your USB device.  These two files are config files responsible for helping syslinux boot to the Windows 7 installation.

The two config files are nt60.0 and syslinux.cfg. When you are copying this to your drive and are prompted to overwrite existing files click Yes.

Now you are finished.  Go and install Windows 7.  But don’t forget Linux is better, you will be back, trust me, you will be back.

Autoit Command Line Parameters. A new approach.

autoit_6_240x100

There are two ways to get command line arguments that are passed to an Autoit script, $cmdLineRaw() and $cmdLine[]. Both allow you to get the arguments to control your script. Read about them here. The problem is that if you want an application to have multiple arguments but don’t what to have the user enter these in a certain order and to be able to distinguish each argument with a “-m or /m [parameter]“. Basically make your Autoit script with command line arguments act as any DOS command line application.

As you may know when you use $cmdLine[] approach each argument has to be in a certain order so that your program can react appropriately to each $cmdLine[1], $cmdLine[2], etc variable. But what if the user accidentally swaps his input and places the data that should go in parameter 1 in paramter 2? Now your script will either give an error or worst manipulate the wrong data. Below I will show you how I got around this:

Here is what we want our application to do, we want there to be two required arguments “-h and -b” both of these require that you have data passed to it and there are two optional arguments “-x and -y” that do not have data passed to it, they are just flags. Once run, we will display a message box showing the Header and Body along with if a flag was set.

First we will define some Global variables that will be place holders for our users input. Next we will create two functions, one called ReadCmdLineParams() which will be get the parameters that are passed on the command line. The second function is our help message called CmdLineHelpMsg() telling the user what each parameter means and how to use the application.

First define the Global Variables:

Global $msgHeader	 	= ""			;Varible for the message header
Global $msgBody			= ""			;Varible for the message body
Global $flagX 			= "False"		;Flag X
Global $flagY 			= "False"		;Flag y

After we set the Global variables we call the ReadCmdLineParams() function, then we will display the message box that will show the output from the command line arguments.

;;Get Parameters
ReadCmdLineParams()
 
;; Display message
MsgBox(0, "MsgHeader: " & $msgHeader, "MsgBody: " & $msgBody & " FlagX: " & $flagX & " FlagY: " & $flagY)

Next we will define the ReadCmdLineParams() function. This function will loop through all command line arguments and based on the specified arguements determine if a flag needs to be set or to go to the next argument to process the data and enter it to one of the Global variables.

Func ReadCmdLineParams() 	;Read in the optional switch set in the users profile and set a variable - used in case selection
 
	;;Loop through every arguement
	;;$cmdLine[0] is an integer that is eqaul to the total number of arguements that we passwed to the command line
	for $i = 1 to $cmdLine[0]
 
		select
			;;If the arguement equal -h
			case $CmdLine[$i] = "-h"
				;check for missing argument
				if $i == $CmdLine[0] Then cmdLineHelpMsg()
 
				;Make sure the next argument is not another paramter
				if StringLeft($cmdline[$i+1], 1) == "-" Then
					cmdLineHelpMsg()
				Else
					;;Stip white space from the begining and end of the input
					;;Not alway nessary let it in just in case
					$msgHeader = StringStripWS($CmdLine[$i + 1], 3)
				endif
 
			;;If the arguement equal  -b
			case $CmdLine[$i] = "-b"
 
				;check for missing arguement
				if $i == $CmdLine[0] Then cmdLineHelpMsg()
 
				;Make sure the next argument is not another paramter
				if StringLeft($cmdline[$i+1], 1) == "-" Then
					cmdLineHelpMsg()
				Else
					;;Stip white space from the begining and end of the input
					;;Not alway nessary let it in just in case
					$msgBody = StringStripWS($CmdLine[$i + 1], 3)
				EndIf
 
			;set the -x flag to True
			case $cmdLine[$i] = "-x"
				$flagX = "True"
 
			;set the -y flag to True
			case $cmdLine[$i] = "-y"
				$flagY = "True"
 
		EndSelect
 
	Next
 
	;Make sure required options are set and if not display the Help Message
	if $msgHeader == "" Or $msgBody == "" Then
		cmdLineHelpMsg()
	EndIf
 
EndFunc

Last we specify the cmdLineHelpMsg() function. This function gets called whenever a user inputs data to the command line incorrectly or without any arguments. It is just a message box that display how to use the application. Once the user presses OK to the message box the application is exited.

Func cmdLineHelpMsg()
	ConsoleWrite('A better way to get the command line parameters' & @LF & @LF & _
					'Syntax:' & @tab & 'cmdLineForBlog.exe [options]' & @LF & @LF & _
					'Default:' & @tab & 'Display help message.' & @LF & @LF & _
					'Required Options:' & @LF & _
					'-h [message]' & @tab & ' Message Header' & @LF & _
					'-b [message]' & @tab & ' Message Body' & @LF & _
					@LF & _
					'Optional Options:' & @LF & _
					'-x ' & @tab & 'Flag X' & @lf & _
					'-y' & @tab &  'Flag Y' & @lf)
	Exit
EndFunc

Once you compile the application as an exe (cmdLineForBlog.exe) go to a command prompt and type:

c:\> cmdLineForBlog.exe -h "Header Message" -b "Body Message" -x -y
or
c:\> cmdLineForBlog.exe  -b "Body Message" -x -y -h "Header Message"
or
c:\> cmdLineForBlog.exe -h "Header Message" -b "Body Message" -y

Now you can put the parameters in any order and still get the desired results.

You can also change the msgbox() function to the consolewrite() function and add #AutoIt3Wrapper_Change2CUI=y to the begining of your application which will display the help message in the DOS command windows instead of popping up a message box. One important note This application does not sanitize any data. Please write the appropriate functions to do so. Do not assume that use will always enter the correct data. If you have any questions or comments please email me at motersho [ at ] gmail [ dot ] com

UPDATE:
This page get a fair amount of traffic but I have received no comments. Since you have managed to read this far can you please leave a comment (g00d or bad) to let me know if this is a viable option for you or if this just doesn’t make sense. Any feed back is good feedback IMHO. Thanks.

Here is the script all at once:

Global $msgHeader	 	= ""			;Varible for the message header
Global $msgBody			= ""			;Varible for the message body
Global $flagX 			= "False"		;Flag X
Global $flagY 			= "False"		;Flag y
 
;;Get Parameters
ReadCmdLineParams()
 
;; Display message
MsgBox(0, "MsgHeader: " & $msgHeader, "MsgBody: " & $msgBody & " FlagX: " & $flagX & " FlagY: " & $flagY)
 
Func ReadCmdLineParams() 	;Read in the optional switch set in the users profile and set a variable - used in case selection
 
	;;Loop through every arguement
	;;$cmdLine[0] is an integer that is eqaul to the total number of arguements that we passwed to the command line
	for $i = 1 to $cmdLine[0]
 
		select
			;;If the arguement equal -h
			case $CmdLine[$i] = "-h"
				;check for missing argument
				if $i == $CmdLine[0] Then cmdLineHelpMsg()
 
				;Make sure the next argument is not another paramter
				if StringLeft($cmdline[$i+1], 1) == "-" Then
					cmdLineHelpMsg()
				Else
					;;Stip white space from the begining and end of the input
					;;Not alway nessary let it in just in case
					$msgHeader = StringStripWS($CmdLine[$i + 1], 3)
				endif
 
			;;If the arguement equal  -b
			case $CmdLine[$i] = "-b"
 
				;check for missing arguement
				if $i == $CmdLine[0] Then cmdLineHelpMsg()
 
				;Make sure the next argument is not another paramter
				if StringLeft($cmdline[$i+1], 1) == "-" Then
					cmdLineHelpMsg()
				Else
					;;Stip white space from the begining and end of the input
					;;Not alway nessary let it in just in case
					$msgBody = StringStripWS($CmdLine[$i + 1], 3)
				EndIf
 
			;set the -x flag to True
			case $cmdLine[$i] = "-x"
				$flagX = "True"
 
			;set the -y flag to True
			case $cmdLine[$i] = "-y"
				$flagY = "True"
 
		EndSelect
 
	Next
 
	;Make sure required options are set and if not display the Help Message
	if $msgHeader == "" Or $msgBody == "" Then
		cmdLineHelpMsg()
	EndIf
 
EndFunc
 
Func cmdLineHelpMsg()
	ConsoleWrite('A better way to get the command line parameters' & @LF & @LF & _
					'Syntax:' & @tab & 'cmdLineForBlog.exe [options]' & @LF & @LF & _
					'Default:' & @tab & 'Display help message.' & @LF & @LF & _
					'Required Options:' & @LF & _
					'-h [message]' & @tab & ' Message Header' & @LF & _
					'-b [message]' & @tab & ' Message Body' & @LF & _
					@LF & _
					'Optional Options:' & @LF & _
					'-x ' & @tab & 'Flag X' & @lf & _
					'-y' & @tab &  'Flag Y' & @lf)
	Exit
EndFunc

How to: Manual Install of the Oracle dbConsole

Here is how to manually install an Oracle database server’s dbConsole service on Windows. You will need to run %ORACLE_HOME%\bin\emca.bat.

First you have to set a couple of system environment variables

c:\>set ORACLE_HOME=c:\path\to\oracle\home
c:\>set ORACLE_SID=DB_SID

Next run the emca.bat file with the parameters -config dbcontrol db

c:\>emca.bat -config dbcontrol db

Next you will be asked a few configuration setting

STARTED EMCA at Oct 12, 2009 3:34:20 PM
EM Configuration Assistant, Version 10.2.0.1.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Enter the following information:
Database SID: DB_SID
Listener port number: 1521
Password for SYS user:
Password for DBSNMP user: Password for SYSMAN user: Password for SYSMAN user: Email address for notifications (optional):email@yourserver.com
Outgoing Mail (SMTP) server for notifications (optional):mail.yourserver.com

It will then ask you to verify the setting that you just entered

You have specified the following settings
Database ORACLE_HOME ................ C:\path\to\oracle\home
Database hostname ................ yourdbserver.com
Listener port number ................ 1521
Database SID ................ DB_SID
Email address for notifications ............... email@yourserver.com
Outgoing Mail (SMTP) server for notifications ...............mail.yourserver.com
-----------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: yes

Once you enter yes it will then display a bunch of log information. In this log will be the path to your Enterprise Management Console. ex. http://:1158/em

Enter the url in your browser and login. You are now all set. This will create the OracleDBConsole server and set it to start automatically.

A few notes. I didn’t know the password for my dbsnmp user account. So I attempted to login and Oracle told me that the account was locked. I then entered the following commands to unlock the account and to change the password.

c:\>sqlplus /nolog
sqlplus>conn sys as sysdba
Enter Password: sqlplus> ALTER USER dbsnmp ACCOUNT UNLOCK;
Account Unlocked
sqlplus>ALTER USER dbsnmp identified by ;
Password Changed.

Thats it.

HOWTO: Send SMTP commands via a bash script and the /dev/tcp device file

Scroll down to script

Today at work, the support staff needed to check and see if a customer’s email server was setup to relay mail via their database server.  Normally when asked, I direct the support staff to the send the SMTP commands via Telnet like so:

You do/type this Server responds with
Telnet to hostname on port 25 220 (then identifies itself – possibly with several lines of 220 + text)
HELO your_domain_name or whatever 250 (followed by human readable message)
MAIL FROM:you@hostname.com (ie, your email address) 250 is syntactically correct (or similar)
RCPT TO:them@someplace_else.com (email address you want to send to) 250 is syntactically correct
DATA Tells you to send data then CRLF period CRLF at end
You type your message then CRLF period CRLF (ie, type a period on a line by itself then hit ENTER) 250
QUIT Signoff message

But I figured instead of telling them the same thing every other week it was time to brush up on my bash scripting skills and learn something new in the process.

I first tried to read in the variables and then send them out to a telnet command but quickly realized that once telnet was executed in the script it would no longer accept the bash variables that I had created.  I knew from previous scripts that I could use the expect commands (more info) but expect is not usually a package that gets installed on a linux server by default and most of these servers are production database servers, which no admin would allow a random package to get installed with out testing it first.

So with expect out of the question it was time for some Google searches which let me to an article from the Linux Journal titled “More on Using Bash’s Built in /dev/tcp File (TCP/IP)“  This struck my interest, first because I didn’t know that this was possible and second because this was the same way that I had done it in the Windows/AutoIT world (I will post more about this later).  Here is the full script that I wrote.  Feel free to use this as you need or if you see a way for me to make it better please let me know.
Script

#!/bin/bash
 
# Written by: Terry Moore
# Created on Date: 2009-10-12
# Test mail relay from a Linux database server 
# Version 0.2 
# Last update 2009-10-13
 
#Body of Email
DATA="The test message has been sent"
 
#Subject of Email
SUBJECT="Mail Relay Test"
 
 
######### Header ##########
echo
echo
echo
echo "***************************************"
echo "*                                                           *"
echo "*             Mail Relay Test App                    *"
echo "*                                                           *"
echo "***************************************"
echo 
echo "Press control+c at any time to cancel"
echo "Please answer all of the following questions:"
echo
 
 
##### Get Mail Server #######
LOOP=0
while [ $LOOP -ne 1  ]
do
	echo -n "Enter Mail Server Name: " ; read MAILSERVER;
	if [ "$MAILSERVER" != '' ] ; then
		LOOP=1
	fi
done
 
 
###### GET PORT ##########
echo -n "Enter Port: [typically 25]: "; read PORT;
if [ "$PORT" = '' ] ; then
	LOOP=1
	PORT="25"
fi
 
###### GET MAIL FROM ##########
echo -n "Enter Mail From: [support@email.com]" ; read MAILFROM
if [ "$MAILFROM" = '' ] ; then
	MAILFROM="support@email.com"
	LOOP=0
fi
 
###### GET MAIL TO ##########
LOOP=0
while [ $LOOP -ne 1 ]
do
	echo -n "Enter Mail To: " ; read MAILTO
	if [ "$MAILTO" != '' ] ; then
		LOOP=1
	fi
done
 
 
#### SEND MAIL via RAW TCP #######
echo 
echo "Connecting to $MAILSERVER on Port $PORT";
echo "Please wait ... "
echo
exec 3<>/dev/tcp/$MAILSERVER/$PORT 
 
if [ $? -ne 0 ] ; then
	echo
	echo "ERROR: Cannot connect to the Mail Server";
	echo "Please check the servername and/or the port number"
	exit
fi
 
echo -en "HELO mail.email.com\r\n"  >&3 
echo -en "MAIL FROM:$MAILFROM\r\n" >&3
echo -en "RCPT TO:$MAILTO\r\n" >&3
echo -en "DATA\r\n" >&3
echo -en "Subject: $SUBJECT\r\n\r\n" >&3
echo -en "$DATA\r\n" >&3
echo -en ".\r\n" >&3
echo -en "QUIT\r\n" >&3
cat <&3
 
 
echo
echo
echo "Check the above output for errors"
echo

I know I have to do more error checking and data sanitizing but you can get the drift as to how to use bash’s builtin /dev/tcp device file to send telnet commands.

More on Using Bash’s Built-in /dev/tcp File (TCP/IP)

One gay man, two lesbians, a three-legged cat and a poisoned curry plot

A gay man tried to poison his lesbian neighbours by putting slug pellets into their curry after he was accused of kidnapping their three-legged cat.

Phish Announces Fall Tour

phish_logo

11.18.09 Cobo Arena, Detroit, MI
11.20.09 U.S. Bank Arena, Cincinnati, OH
11.21.09 U.S. Bank Arena, Cincinnati, OH
11.22.09 War Memorial at Oncenter , Syracuse, NY
11.24.09 Wachovia Center, Philadelphia, PA
11.25.09 Wachovia Center, Philadelphia, PA
11.27.09 Times Union Center, Albany, NY
11.28.09 Times Union Center, Albany, NY
11.29.09 Cumberland County Civic Center, Portland, ME
12.02.09 Madison Square Garden , New York, NY
12.03.09 Madison Square Garden, New York, NY
12.04.09 Madison Square Garden, New York, NY
12.05.09 John Paul Jones Arena, Charlottesville, VA

I would love to do the Detroit to Cincinnati run.  Now, if I only had the funds.  Plus this conflicts with the OSU vs Michigan game on the 21st.