find_wwpn

#!/bin/ksh
# Written by John Rigler
# 10/04/2006

# Figure out what parameter was given

   case "$1"
   in
     fscsi?*)  CMD="fscsi" ;;
     fcs?*)    CMD="fcs" ;;
     *)        CMD="usage";;
   esac

# Get fcs if you were given fscsi

if [[ $CMD = fscsi ]]
        then

lsdev -Cl $1 | cut -c 18-22 | read FCSNO
lsdev -Cc adapter | grep $FCSNO | read FCS TRASH
        fi

if [[ $CMD = fcs ]]
        then
        FCS=$1
        fi

# Run it

if [[ $CMD != usage ]]
        then

lscfg -vl $FCS  | grep Network | read LINE

for SNIPPET in 29-30 31-32 33-34 35-36 37-38 39-40 41-42 43-44
        do
        echo $LINE | cut -c $SNIPPET
        done | xargs -n8 | sed 's/\ /:/g'

        else
        echo "Usage: $0 fcs# or fscsi#  <---- will return WWPN"
        fi

Setup dsh and dcp

dsh is an extension of ssh which allows you to run commands in parallel on a number of serves at once.
To set up dsh to work, first set the following variables:

export DSH_LIST=/etc/dsh.hosts
export DSH_NODE_RSH=/usr/bin/ssh
export DSH_NODE_RCP=/usr/bin/scp
export DCP_DEVICE_RCP=/usr/bin/scp
export DCP_NODE_RCP=/usr/bin/scp

/etc/dsh.hosts is just a list of fully qualified host names.

Also, pipe your dsh results into ‘dshbak -c’ and it will organize them nicely for you.

Spreadsheet::WriteExcel

This is a fabulous implementation of perl:
cpan WriteExcel page

Below is one of Mr. McNamara’s scripts with a few changes, I include is just as an example:

#!/usr/bin/perl -w

##############################################################################
#
# A simple example of converting some Unicode text to an Excel file using
# Spreadsheet::WriteExcel and perl 5.8.
#
# This example generates some Thai from a file with ISO-8859-11 encoded text.
#
#
# reverse('©'), September 2004, John McNamara, jmcnamara@cpan.org
#



# Perl 5.8 or later is required for proper utf8 handling. For older perl
# versions you should use UTF16 and the write_unicode() method.
# See the write_unicode section of the Spreadsheet::WriteExcel docs.
#
require 5.008;

use strict;
use Spreadsheet::WriteExcel;


my $workbook  = Spreadsheet::WriteExcel->new("/buxs/htdocs/sample.xls");
my $worksheet = $workbook->add_worksheet('info');
#   $worksheet->set_column('A:A', 20);


my $file = 'excel_test.txt';

open FH, '<:encoding(iso-8859-11)', $file  or die "Couldn't open $file: $!\n";

my $row = 0;

while () {
    next if /^#/; # Ignore the comments in the sample file.
    chomp;
    my $line = $_;
    my @fields = split /\t/, $line;
    my $col = 0;
      foreach(@fields)
        {
        $worksheet->write($row, $col++, $_);
        }
   $row++;
}

close FH;

open FHT, '<:encoding(iso-8859-11)', 'excel_test2.txt'  or die "Couldn't open $file: $!\n";

$worksheet = $workbook->add_worksheet('info2');

$row = 0;

while () {
    next if /^#/; # Ignore the comments in the sample file.
    chomp;
    my $line = $_;
    my @fields = split /\t/, $line;
    my $col = 0;
      foreach(@fields)
        {
        $worksheet->write($row, $col++, $_);
        }
   $row++;
}

close FHT;

planarmap – tells you what is where

code:


lsdev -Cc adapter | grep "^ent" | while read A B
do
lscfg -vl $A
done | grep Network | cut -c 37- | tr 'A-Z' 'a-z' | while read MAC
        do
        echo $MAC | cut -c 1-4 | read MAC1
        echo $MAC | cut -c 5-8 | read MAC2
        echo $MAC | cut -c 9-12 | read MAC3
        echo $MAC1.$MAC2.$MAC3
        done

example:

$ planarmap
001.DQDGMFC------------------------------------------
---pci25---------------------------------------------
        pci29 sisscsia0 PCI-X Ultra320 SCSI Adapter
T7      pci30 ent0 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
T6      pci30 ent1 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
---pci26---------------------------------------------
C3-T1   pci31 fcs0 FC Adapter
C4-T1   pci32 fcs1 FC Adapter
---pci27---------------------------------------------
        pci33 sisscsia1 PCI-X Ultra320 SCSI Adapter

Read Julian Date

#!/bin/ksh93

let JULIAN=$1

# Sets a month/day pair for comparison

if  [[ `leapyear $2` != true ]]
        then
        JULIANSTR="12.334 11.304 10.273 9.243 8.212 7.181 6.151 5.120 4.90 3.59 2.31 1.0"
        LASTDAY=365
        else
        JULIANSTR="12.335 11.305 10.274 9.244 8.213 7.182 6.152 5.121 4.91 3.60 2.31 1.0"
        LASTDAY=366
fi

# Exists if the Julian Date is invalid

if [[ $JULIAN -gt $LASTDAY ]]
        then
        exit
        fi

# Main loop, only prints on a match

for MONJUL in $JULIANSTR
        do
        echo $MONJUL | sed 's/\./\ /g' | read MON JUL
        if [[ $JULIAN -gt $JUL ]]
        then
        let DAY=JULIAN-JUL
        echo "$MON/$DAY/$2"
        exit
        fi
done

Using jTDS to connect to a Windows SQL DB from AIX

The jTDS drivers may be easier to configure than freeTDS in your unix environment to allow database updates to windows. You have to compile the source yourself, but you would be doing in java rather than C. Here is a link to sourceforge:

jTDS sourceforge
If this doesn’t work, I have a version of the jar file that it would compile and also the subdirectories of compiled class code which I know runs at AIX 5.3:

jtds-1.2.jar

jtds-1.2.tar

The following example script will make a simple database connection and is pretty self-explanatory, it requires that the ‘net’ directory structure exist because I am not clever enough to figure out how to use jar files yet and I just un-jarred it with the -x command:

/* 
Copyright 2003 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use of this software is authorized pursuant to the terms of the license found at
http://developer.java.sun.com/berkeley_license.html.

Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

- Redistribution of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

- Redistribution in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Neither the name of Sun Microsystems, Inc. or the names of contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

This software is provided "AS IS," without a warranty of any kind.
ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICORSYSTEMS, INC. ("SUN")
AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN
IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You acknowledge that this software is not designed, licensed or intended for
use in the design, construction, operation or maintenance of any nuclear
facility.


*/


/*
 * Copyright 2003 Sun Microsystems, Inc.  ALL RIGHTS RESERVED.
 * Use of this software is authorized pursuant to the terms of the license found at
 * http://developer.java.sun.com/berkeley_license.html.
 */

import java.sql.*;
import net.sourceforge.jtds.jdbc.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


class MS_SQL_Execute {

  public static void main(String args[]) {

    String url = "jdbc:jtds:sqlserver://nad0019st01:1433/DBAReporting";
    Connection con;
    Statement stmt;
    String query = "";
    String lastcol = "";

    File file = new File("execute.sql");

FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);

      // Here BufferedInputStream is added for fast reading.
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      // dis.available() returns 0 if the file does not have more lines.
      while (dis.available() != 0) {

      // this statement reads the line from the file and print it to
        // the console.

        query = dis.readLine();
        System.out.println(query);


    try {
      Class.forName("net.sourceforge.jtds.jdbc.Driver");

    } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
    }

    try {
      con = DriverManager.getConnection(url,
                   "AIXUser", "P@ssw0rd");

      stmt = con.createStatement();

  /*    stmt.executeUpdate("insert into SUPPLIERS " +
                   "values(49, 'Superior Coffee', '1 Party Place', " +
         "'Mendocino', 'CA', '95460')");
 */
      ResultSet rs = stmt.executeQuery(query);

/*
      ResultSetMetaData rsmd = rs.getMetaData();
        int numColumns = rsmd.getColumnCount();

// Get the column names; column indices start from 1
        String FirstcolumnName = rsmd.getColumnName(1);
        for (int i=2; i
					

How to set up ssh to allow you to run remote commands

Configuration for ssh is done in two places:

  1. In the /etc/ssh directory as root
  2. In the user’s .ssh subdirectory

From a system perspective, /etc/ssh/sshd_config may need to be changed in order to restrict ssh version 1, allow root login (PermitRootLogin) or make other various changes. The sshd daemon can be restarted without disrupting current connections. In /etc/ssh is also a file called ssh_known_hosts. If you will be using ssh as the root user, I recommend making a symbolic link between root’s known_hosts file and this one. Then make sure and connect to any new hosts as root before connecting as a user. In this way, you will maintain a global known_hosts command and individual users will not have to maintain their individual host lists.

From a user perpective, ssh is set up by creating a public and private key pair with the ssh-keygen command:

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Created directory '/home/username/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
45:36:66:b8:39:bc:e0:84:ae:eb:50:e3:28:ec:47:0a username@hostname

$ cd .ssh
$ ls -l
total 16
-rw-------   1 username    staff          1675 Nov 24 12:40 id_rsa
-rw-r--r--   1 username    staff           401 Nov 24 12:40 id_rsa.pub

The file ‘id_rsa’ is your private key and should be kept on any system that is trying to ssh out. The file ‘id_rsa.pub is your public key. Give this to other people so that they can put in into a file on their side called ‘authorized_keys’. If you want to test ssh by connecting to yourself, simply move or copy ‘id_rsa.pub’ to ‘authorized_keys’. At this point you should be able to test ssh by connecting to yourself:

$ pwd
/home/username/.ssh
$ ls -la
total 16
drwx------   2 netiq    staff           256 Nov 24 12:50 .
drwxr-xr-x   3 netiq    staff           256 Nov 24 12:47 ..
-rw-------   1 netiq    staff          1675 Nov 24 12:47 id_rsa
-rw-r--r--   1 netiq    staff           401 Nov 24 12:47 id_rsa.pub
$ mv id_rsa.pub authorized_keys
$ ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
 RSA key fingerprint is 3b:4b:af:d1:b3:ec:51:83:96:48:ea:8e:09:83:d4:80.
 Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added 'localhost,127.0.0.1' (RSA) to the list of known hosts.
Last unsuccessful login: Mon Nov 24 12:43:24 CST 2008 on ssh from 10.32.12.45
Last login: Mon Nov 24 12:48:14 CST 2008 on /dev/pts/1 from 10.32.12.45
**********************************************************
*                                                        *
*                                                        *
*  Welcome to AIX Version 5.3!                           *
*                                                        *
*                                                        *
*  Please see the README file in /usr/lpp/bos            *
*  for information pertinent to                          *
*  this release of the AIX Operating System.             *
*                                                        *
*                                                        *
**********************************************************
$ exit
Connection to localhost closed.

Generally you will no only connect to yourself, but you will also not use the name ‘localhost’. After running this test, however, you will have created a new file called ‘known_hosts’ that contains a bit of data which describes this server. This is a human-readable file that will collect information about all of the servers that you connect to. This is the file that is over-ridden by /etc/ssh/ssh_known_hosts.

Once ssh is configured, scp and sftp will also work. If you are a micro-focus cobol user, you might see a different ‘scp’ which will seem wierd, simply change your path to fix this or fully qualify scp:

psoft$scp
PVER1
GERR00Not enough parameters
psoft{fsprd75}$whence scp
/usr/lpp/cobol/bin/scp
psoft$/usr/bin/scp
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 [...] [[user@]host2:]file2

Social Networking sprawl

So I have tried to avoid all those cool little links at the bottom of stories that say dig.it and what not but I figured that I might look into them a little more and so I clicked randomly on a show me more button. Below looks like a good starting place, a list which it would seem encompasses at least the linking and sharing aspect of all this. In my idle hours, I will try to find more and make sense of all this stuff. For example, I am on LinkedIn and have heard of Twitter and Facebook, but what here is really helpful and can make what I do, better.