I work as an sysadmin in large data center full of Sun HW. Yestarday I stand in front of task to get verions of our HW SPs. First thing which crossed my mind was to take leverage of Ops Center – Sun (Oracle) management tool which is able to give you SP version in asset detail. It can even upgrade it! Unfortunately there is no way how to report all your assets with firmware (SP) version :o( I went all the way down from Report function in web UI, through CLI to Posgres DB directly. No chance to quickly acquire such list.

OK, lets try scripting! I used Expect scripting that we used in our team before for very similar tasks. First I wrote a generic script for ELOM and ILOM:

#!/usr/bin/expect -f
# for ILOM and ELOM expects 3 parameters 
#	- username
#	- machine name
#	- password
# returns 2 in case of wrong password
# returns 3 in case of unexpected end 
# (connection refused, or different behavior)
set timeout 3 # set how long it waits for expected output
spawn ssh [lindex $argv 0]@[lindex $argv 1]
        expect {
                "efused" { # connection refused
                                        exit 3
                }
                "(yes/no)" { # a new key, accept
                        send "yes\r"
                }
                end
        }
        expect { # nice word, huh? 
                    # we do not know if it is 
                    # Password or password
                "assword:" {
                        send "[lindex $argv 2]\r"
                }
                end
        }
        expect { # we have probably wrong password
                "assword:" {
                        exit 2
                }
                timeout {
                        exit 3
                }
                "Version" {
                }
                end
	}
	expect {
		">" {
			send "exit"
		}
		end
	}

Now the bash wrapper script which receive on stdin space separated list and output to a file results:

#!/bin/bash
# This script login to the ELOM/ILOM SP and return version
# Autor: nax
# 
# Get a list seperated by space from standard output
# colums:
# 1. hostname/IP
# 2. username for ssh login
# 3. password for ssh login

while read SP USER PASS ; do
	LOM=`expect ilom.ex $USER $SP $PASS | fgrep 'Lights' | \
     sed 's/Sun Microsystems Embedded Lights Out Manager$/ELOM/' | \
     sed 's/Sun(TM) Integrated Lights Out Manager$/ILOM/'`
	VER=`expect ilom.ex $USER $SP $PASS | fgrep 'Version' | \
     sed 's/Firmware Version: //' | sed 's/Version //'`
	echo "$SP,$LOM,$VER" >> out.csv
done

Napsat komentář