#!/bin/sh # Get Sun Solaris information # (has some PmWiki isms in the output, but still useful) # # Copyright (C) 2009, Christopher J. Cox # Copyright (C) 2009, Sterling Commerce, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Note: Uses dmidecode (if found). This was written before smbios on x86 Solaris. # dmidecode/smbios are NOT required. # os=sunos LANG=C wikibanner="1" wikipage="1" do_banner() { if [ "$wikibanner" ]; then name="$1" title="$2" echo "![[#${name}]] [[{*\$FullName}#${name}|${title}]]" fi } hexoctet_todec() { hexoctect="$1" oct1=`expr "$hexoctect" : '\(..\)......' | tr '[a-f]' '[A-F]'` oct2=`expr "$hexoctect" : '..\(..\)....' | tr '[a-f]' '[A-F]'` oct3=`expr "$hexoctect" : '....\(..\)..' | tr '[a-f]' '[A-F]'` oct4=`expr "$hexoctect" : '......\(..\)' | tr '[a-f]' '[A-F]'` dec=`echo "ibase=16;$oct1;$oct2; $oct3;$oct4" | bc | tr '\012' '.'` echo "${dec}" | sed 's/.$//' } dump_hw_vars() { prefix="$1" hw_vars=`set | grep '^hw_' | grep '=' | cut -f1 -d= | sort -u` for hw_var in $hw_vars; do eval hw_val="\$${hw_var}" echo "$hw_val" done | while IFS=: read name value;do if [ ! "$name" -o ! "$value" ]; then continue fi name=`echo "$name" | tr ' -' '__'` value=`echo "$value" | sed -e 's/^[ ]*//' -e 's/[ ][ ]*/ /g'` if [ "$wikipage" ]; then echo "(:${prefix}_${name}:${value} :)" else echo "${prefix}_${name}:${value}" fi done } do_hw() { os="$1" shift for fnname in $*; do result=`hw_${os}_${fnname}` lc=`echo "$result" | wc -l` if [ $lc -gt 1 -a "$wikipage" ]; then echo ">>class='hw_$fnname hw_${os}_${fnname}'<<" echo "$result" echo ">><<" else echo "$result" fi done } upperfirst () { value="$1" firstlet=`echo $value | sed 's/^\(.\).*/\1/'` rest=`echo $value | sed 's/^.\(.*\)/\1/'` firstlet=`echo "$firstlet" | tr '[a-z]' '[A-Z]'` echo "${firstlet}${rest}" | sed -e 's/[(][Rr][)]//g' \ -e 's/[(][Tt][Mm][)]//g' \ -e 's/[@].*$//' \ -e 's/[^A-Za-z0-9-][^A-Za-z0-9-]*/-/g' \ -e 's/[-]*$//' } cpucat() { type="$1" subtype="$2" cputype="" if echo "$type" | grep -i SPARC >/dev/null 2>&1; then cputype="SPARC" elif echo "$type" | grep -i Intel >/dev/null 2>&1; then cputype="Intel" elif echo "$type" | grep -i Itanium >/dev/null 2>&1; then cputype="Intel" elif echo "$type" | grep -i '[0-5]86' >/dev/null 2>&1; then cputype="Intel" elif echo "$type" | grep -i AMD >/dev/null 2>&1; then cputype="AMD" elif echo "$type" | grep -i PowerPC >/dev/null 2>&1; then cputype="PowerPC" else cputype="$type" fi cputype=`upperfirst "$cputype"` cpusubtype="$subtype" case "$cputype" in Intel) if echo "$subtype" | grep -i XEON >/dev/null 2>&1; then cpusubtype="Xeon" elif echo "$subtype" | grep -i Pentium >/dev/null 2>&1; then cpusubtype="Pentium" elif echo "$subtype" | grep -i Celeron >/dev/null 2>&1; then cpusubtype="Celeron" elif echo "$subtype" | grep -i "Core[^2]*Duo" >/dev/null 2>&1; then cpusubtype="Core-Duo" elif echo "$subtype" | grep -i "Core.*2.*Duo" >/dev/null 2>&1; then cpusubtype="Core2-Duo" fi ;; AMD) if echo "$subtype" | grep -i Opteron >/dev/null 2>&1; then cpusubtype="Opteron" fi ;; SPARC) cpusubtype="$subtype" ;; esac cpusubtype=`upperfirst "$cpusubtype"` echo "${cputype:+$cputype}${cpusubtype:+ $cpusubtype}" } memorycat() { type="$1" value="$2" value=`echo "$value" | awk '{printf("%d",$0);}'` if [ "$type" = kb ]; then echo "Memory-Less-256M" elif [ "$type" = gig ]; then if expr ${value} \< 3 >/dev/null; then echo "Memory-1G-3G" elif expr ${value} \> 8 >/dev/null; then echo "Memory-Over-8G" elif expr ${value} \> 4 >/dev/null; then echo "Memory-4G-8G" else echo "Memory-3G-4G" fi elif [ "$type" = meg ]; then if expr ${value} \< 256 >/dev/null; then echo "Memory-Less-256M" elif expr ${value} \> 512 >/dev/null; then echo "Memory-512M-1G" else echo "Memory-256M-512M" fi fi } all () { os="$1" do_hw "$os" hostname os memory cpuinfo interfaces fs disks } dmiout() { type="$1" if [ -x /usr/local/sbin/dmidecode ]; then /usr/local/sbin/dmidecode | awk ' BEGIN { type="'"$type"'"; } /^$/ { inprocessor=0; incache=0; inl2cache=0; insysinfo=0; } /^Processor Information/ { inprocessor=1; } /^Cache Information/ { incache=1; } /^System Information/ { insysinfo=1; } { if (incache && $0 ~ /^ Configuration: .*Level 2.*/) { inl2cache=1; } if (inprocessor && type == "cpu") print; else if (inl2cache && type == "cache") print; else if (insysinfo && type == "sysinfo") print; else if (type == "") print; next; }' fi } hw_sunos_hostname() { do_banner Hostname "Host Information" hostname=`hostname` uptime=`uptime` hostid=`hostid` model=`uname -i` smbiosout="" if [ -x /usr/sbin/smbios ]; then smbiosout=`/usr/sbin/smbios 2>/dev/null` dmi=`echo "$smbiosout" | awk ' / SMB_TYPE_SYSTEM / { sysinfo=1; next; } /^[ ][ ]*/ { if (sysinfo) { print; } } /^[^ ]/ { if (sysinfo) { exit; } }' | grep ':' | sed \ -e 's/^[ ]*//' \ -e 's/[ ]*$//' \ -e 's/[ ]*:[ ]*/:/' \ -e 's/Serial No:/Serial:/' \ -e 's/Serial Number:/Serial:/' \ -e 's/Product Name:/Product:/' \ -e 's/"//g'` elif [ -x /usr/local/sbin/dmidecode ]; then dmidecodeout=`/usr/local/sbin/dmidecode` if [ "$dmidecodeout" ]; then dmi=`echo "$dmidecodeout" | awk ' /^[ ]*System Information/ { sysinfo=1; next; } /^ .*/ { if (sysinfo) { print; } } /^[^ ]/ { if (sysinfo) { exit; } }' | grep ':' | sed \ -e 's/^[ ]*//' \ -e 's/[ ]*$//' \ -e 's/[ ]*:[ ]*/:/' \ -e 's/Serial No:/Serial:/' \ -e 's/Serial Number:/Serial:/' \ -e 's/Product Name:/Product:/' \ -e 's/"//g'` fi fi if [ -x /usr/platform/$model/sbin/prtdiag ]; then # prtdiag sometimes never returns, wait 5 seconds and kill it prtdiagout=`(/usr/platform/$model/sbin/prtdiag & pid=$!; sleep 5;kill $pid)` chkmodel=`echo "$prtdiagout" | grep 'System Configuration: .*220R.*' | cut -d: -f2-` if [ "$chkmodel" ]; then model="SUNW,Sun-Fire-220R" fi elif [ "" -a -x /usr/sfw/bin/ipmitool ]; then if [ ! -r /tmp/fru.out ]; then /usr/sfw/bin/ipmitool fru >/tmp/fru.out fi out=`cat /tmp/fru.out` out=`echo "$out" | awk ' /^FRU.* mb.fru .*/ { mb=1; next; } /^FRU.*/ { mb=0; } { if (mb) { print; } }'` echo "$out" model=`echo "$out" | sed -n 's/Product Name[ ]*:[ ][ ]*\([^ ].*[^ ]\)[ ]*$/\1/p'` fi if [ "$dmi" ]; then product=`echo "$dmi" | sed -n -e 's/.*Product[^:]*:\([^(]*\).*/\1/p' | sed 's/[ ][ ]*$//' | tr ' /' '--'` else product=`echo "$model" | sed -e 's/SUNW,//' \ -e 's/[ ][ ]*/ /g' \ -e 's/^\([^(][^(]*\).*/\1/' \ -e 's/^[ ][ ]*//' \ -e 's/[ ][ ]*$//' \ -e 's,/,-,g' | tr ' _,()' '-----'` fi if [ ! "$model" ]; then if [ -x /usr/sbin/prtconf ]; then out=`/usr/sbin/prtconf -pv | egrep 'banner-name|device-type|Node|name:'` model=`echo "$out" | sed -n -e 's/(TM)//' \ -e 's/.*banner-name:[ ]*.\(.*\).[ ]*$/\1/p'` fi if [ ! "$model" ]; then model=`uname -i` else model=`echo "$model" | head -1` fi fi product=`upperfirst "$product"` hw_hostid="$hostid" hw_product="Class: $product" hw_out="$dmi" hw_hostname="Hostname: $hostname" hw_uptime="Uptime: $uptime" dump_hw_vars Host # wiki output if [ "$hostname" ]; then echo "$hostname" fi if [ "$uptime" ]; then echo " $uptime" fi if [ "$hostid" ]; then echo " Hostid: ${hostid}" fi if [ "$model" ]; then echo " Model: ${model}" fi if [ "$hw_out" ]; then echo "$hw_out" | awk -F: ' { name=$1; name=name":"; val=$2; printf(" %-20s%s\n", name,val); }' fi if [ "$product" ]; then echo "(:include Hardware/$product:)" echo "[[!$product]]" fi } hw_sunos_os() { do_banner OS "OS Version" class='Solaris' if grep 'OpenSolaris' /etc/release >/dev/null 2>&1; then class='OpenSolaris' fi uname=`uname -a` version=`uname -r | sed 's/[.]/-/g'` mach=`mach | tr [a-z] [A-Z]` submach=`uname -m` if [ "$uname" ]; then hw_uname="Uname: $uname" fi if [ "$version" ]; then hw_version="Version: SunOS-$version" fi if [ "$mach" ]; then hw_arch="Arch: $mach" fi if [ "$submach" ]; then hw_subarch="SubArch: $submach" fi hw_class="Class: $class" update="SunOS${version:+-$version}${mach:+-$mach}" hw_update="Update: $update" dump_hw_vars Os # Wiki output echo "[[!$class]] [[!$class-$mach]] ${version:+[[!SunOS-$version]]} ${version:+[[!SunOS-$version-$mach]]}" } hw_sunos_interfaces() { do_banner NetworkIf "Network Interfaces" # Assume primary interface device is one associated with # default gateway (ipv4). netstatout=`netstat -rn -f inet` netstatgwout=`echo "${netstatout}" | grep UG | grep '^0\.0\.0\.0' |head -1` if [ ! "$netstatgwout" ]; then # hope one that starts with 0.0.0.0 is def gw netstatgwout=`echo "${netstatout}" | grep '^0\.0\.0\.0' |head -1` fi if [ ! "$netstatgwout" ]; then # hope one that starts with default is def gw netstatgwout=`echo "${netstatout}" | grep '^default' |head -1` fi gateway=`echo "$netstatgwout" | awk '{print $2}'` primdev=`echo "$netstatgwout" | awk '{print $6}'` # Taking our chances here. Why doesn't Solaris show the device # associated with the gateway? # Choose the interface asssociated with multicast (pick and hope # first one). # if [ ! "$primdev" ]; then netstatranout=`netstat -ran -f inet| grep '^224\.0\.0\.0' |head -1` primdev=`echo "$netstatranout" | awk '{print $6}'` fi # smash ifconfig v4 all into set of one liners ifconfigoutv4=`/sbin/ifconfig -a4 2>/dev/null` if [ ! "$ifconfigoutv4" ]; then ifconfigoutv4=`/sbin/ifconfig -a 2>/dev/null` fi ifconfigflatoutv4=`echo "${ifconfigoutv4}" | awk ' /^[^ ]/ { dev=$1; } { if (dev != olddev) { if (olddev != "") print devline; olddev=dev; devline=$0; } else { devline=devline " " $0; } } END { if (devline != "") print devline; }'` ifconfigoutv6=`/sbin/ifconfig -a6 2>/dev/null` ifconfigflatoutv6=`echo "${ifconfigoutv6}" | awk ' /^[^ ]/ { dev=$1; } { if (dev != olddev) { if (olddev != "") print devline; olddev=dev; devline=$0; } else { devline=devline " " $0; } } END { if (devline != "") print devline; }'` # Wireless elements if [ -x /usr/sbin/iwconfig ]; then iwconfigout=`/usr/sbin/iwconfig 2>/dev/null` iwconfigflatout=`echo "${iwconfigout}" | awk ' /^[^ ]/ { dev=$1; } { if (dev != olddev) { if (olddev != "") print devline; olddev=dev; devline=$0; } else { devline=devline " " $0; } } END { if (devline != "") print devline; }'` iwnetsalive=`echo "${iwconfigflatout}" | awk '{print $1}' | sed 's/:$//'` fi # Get live interfaces netsalive=`echo "${ifconfigflatoutv4} ${ifconfigflatoutv6}" | grep '[<]UP,.*' | grep '.*[,]RUNNING[,].*' | awk '{print $1}' | sed 's/:$//' | sort -u | tr '\012' ' '` primdev=${primdev:=Unknown} devconfigoutv4=`echo "$ifconfigflatoutv4" | grep "^${primdev}:"` if [ "$devconfigoutv4" ]; then # try to parse ifconfig hwaddr=`echo "${devconfigoutv4}" | sed -n 's/.*ether[:]*[ ]*\([^ ]*\).*/\1/p'` ipv4=`echo "${devconfigoutv4}" | sed -n 's/.*inet[:]*[ ]*\([^ ]*\).*/\1/p'` netmask=`echo "${devconfigoutv4}" | sed -n 's/.*netmask[:]*[ ]*\([^ ]*\).*/\1/p'` broadcast=`echo "${devconfigoutv4}" | sed -n 's/.*broadcast[:]*[ ]*\([^ ]*\).*/\1/p'` status=`echo "${devconfigoutv4}" | sed -n 's/.*[<]UP.*[,]RUNNING[,]*.*/UP/p'` if [ ! "$status" ]; then status="DOWN" fi mtu=`echo "${devconfigoutv4}" | sed -n 's/.* mtu[:]*[ ]*\([^ ]*\).*/\1/p'` else primdev="Unknown" fi devconfigoutv6=`echo "$ifconfigflatoutv6" | grep "^${primdev}:"` if [ "$devconfigoutv6" ]; then ipv6=`echo "${devconfigoutv6}" | grep ADDRCONF | grep IPv6 | sed -n 's/.*inet6[:]*[ ]*\([^ ]*\).*/\1/p'` fi # Rudiments, your boss doesn't understand networking... so # all he wants it the IP associated with a "name" (which has # little to do with networking). hname=`hostname` if [ -x /usr/sbin/nslookup ]; then nsinfo=`/usr/sbin/nslookup -query=any $hname | sed '1,2d'` if [ ! "$ipv4" ]; then # Assume first one is the right IP ipv4=`echo "$nsinfo" | grep 'Address:' | cut -f2 -d: | head -1` if [ ! "$ipv4" ]; then ipv4=`echo "$nsinfo" | grep 'internet address =' | cut -f2 -d= | head -1` fi fi if [ ! "$ipv6" ]; then ipv6=`echo "$nsinfo" | grep 'has AAAA address' | awk '{print $NF}' | head -1` if [ ! "$ipv6" ]; then ipv6=`echo "$nsinfo" | grep 'IPv6 address =' | cut -f2 -d= | head -1` fi fi # If there is descriptive TXT, assume dhcp dhcp=`echo "$nsinfo" | grep 'text ='` # Query local default DNS for names for ip vars if [ "$ipv4" ]; then ipv4dnsname=`/usr/sbin/nslookup $ipv4 | grep 'Name:' | cut -f2 -d: | sed 's/[.]$//'` if [ ! "$ipv4dnsname" ]; then ipv4dnsname=`/usr/sbin/nslookup $ipv4 | grep 'name =' | cut -f2 -d= | sed 's/[.]$//'` fi fi # On Solaris you have to use dig to do reverse # lookups for ipv6. if [ "$ipv6" -a -x /usr/sbin/dig ]; then hipv6=`echo "$ipv6" | cut -f1 -d/` digout=`/usr/sbin/dig -x $hipv6 +short 2>/dev/null` if [ ! "$digout" ]; then digout=`/usr/sbin/dig -x $hipv6 +pfmin 2>/dev/null` ipv6dnsname=`echo "$digout" | grep PTR | awk '{print $NF}' | sed 's/[.]$//'` else ipv6dnsname=`echo "$digout" | sed 's/[.]$//'` fi fi fi # Last resort for ipv4 if [ ! "$ipv4" ]; then # use ping, every Solaris should have it?? ping4info=`ping -A inet -s $hname 56 1 | grep 'bytes from'` if [ ! "$ping4info" ]; then ping4info=`ping -s $hname 56 1 | grep 'bytes from'` fi ipv4=`expr "$ping4info" : '.*[(]\([^)][^)]*\).*'` fi # Get DNS info from resolv.conf if [ -r /etc/resolv.conf ]; then nameservers=`sed -n 's/^nameserver[ ][ ]*\(.*\)/\1/p' /etc/resolv.conf | tr '\012' ' '` search=`sed -n 's/^search[ ][ ]*\(.*\)/\1/p' /etc/resolv.conf | tr '\012' ' '` if [ ! "$search" ]; then search=`sed -n 's/domain[ ][ ]*\(.*\)/\1/' /etc/resolv.conf | tr '\012' ' '` fi fi interfaces=`/sbin/ifconfig -a | grep "^[^ ]" | cut -f1 -d: | grep -v lo0 | sort -u 2>/dev/null` for device in $interfaces;do case "$device" in le*) duplex="Half" speed="10" ;; ce*) # Determine the ce interface number INSTANCE=`/usr/bin/echo $device | cut -c 3-` duplex=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_duplex | /usr/bin/awk '{ print $2 }'` case "$duplex" in 1) duplex=Half ;; 2) duplex=Full ;; esac speed=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_speed | /usr/bin/awk '{ print $2 }'` ;; *) if [ -x /usr/sbin/dladm ]; then speed=`/usr/sbin/dladm show-ether -p -o SPEED-DUPLEX $device 2>/dev/null| cut -f1 -d'-'` gigspeed=` expr "$speed" : '\([0-9][0-9]*\)G'` if [ "$gigspeed" ]; then speed=`expr $gigspeed * 1000` fi megspeed=` expr "$speed" : '\([0-9][0-9]*\)M'` if [ "$megspeed" ]; then speed=$megspeed; fi if [ ! "$speed" ]; then speed=`/usr/sbin/dladm show-dev $device 2>/dev/null | sed -n 's/.*speed: \([0-9][0-9]*\).*/\1/p'` fi duplex=`/usr/sbin/dladm show-ether -p -o SPEED-DUPLEX $device 2>/dev/null | cut -f2 -d'-'` if [ ! "$duplex" ]; then duplex=`/usr/sbin/dladm show-dev $device 2>/dev/null | sed -n 's/.*duplex: \([^ ][^ ]*\).*/\1/p'` fi fi if [ ! "$speed" -a -x /usr/sbin/ndd ]; then speed=`/usr/sbin/ndd -get /dev/$device link_speed 2>/dev/null` duplex=`/usr/sbin/ndd -get /dev/$device link_duplex 2>/dev/null` fi if [ ! "$duplex" ]; then duplex=`/usr/sbin/ndd -get /dev/$device link_mode 2>/dev/null` fi if [ ! "$speed" ]; then INTERFACE_TYPE=`expr "$device" : '^\([^0-9]*\)'` INTERFACE_NUM=`expr "$device" : '^[^0-9]*\(.*\)'` /usr/sbin/ndd -set /dev/$INTERFACE_TYPE instance $INTERFACE_NU 2>/dev/nullM speed=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_speed 2>/dev/null` duplex=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_mode 2>/dev/null` fi if [ ! "$speed" ]; then speed=`kstat -n /dev/$device 2>/dev/null| grep "speed" | awk '{print $2}'` fi if [ ! "$duplex" ]; then duplex=`kstat -n /dev/$device 2>/dev/null| egrep "link_mode|duplex" | awk '{print $2}'` fi case "$duplex" in 0) duplex="Half" ;; 1) duplex="Full" ;; 2) duplex="Full" ;; f) duplex="Full" ;; h) duplex="Half" ;; full) duplex="Full" ;; half) duplex="Half" ;; *) duplex="Unknown" ;; esac case "$speed" in 0) speed="10" ;; 1) speed="100" ;; 1000) speed="1000" ;; esac if [ $speed -gt 1000 ]; then speed=`expr $speed / 1000000` fi ;; esac speedout="${speedout} $device: $speed Mbit $duplex duplex" done # Query for fibre info if [ -x /usr/sbin/fcinfo ]; then fcinfoout=`/usr/sbin/fcinfo hba-port` fi if [ "$fcinfoout" ]; then fcinterfaces=`echo "$fcinfoout" | sed -n 's/^HBA Port WWN: \(.*\)/\1/p' |tr '\012' ' '` fcspeeds=`echo "$fcinfoout" | sed -n 's/ Current Speed: \(.*\)/\1/p' | tr '\012' ' '` fcmodels=`echo "$fcinfoout" | sed -n 's/ Model: \(.*\)/\1/p' | tr '\012' ' '` fi speed=`echo "$speedout" | grep "^${primdev}:" | awk '{print $2}'` duplex=`echo "$speedout" | grep "^${primdev}:" | awk '{print $4}'` if [ "$fcspeeds" ]; then hw_fcspeeds="FCSpeed: $fcspeeds" fi if [ "$fcmodels" ]; then hw_fcmodels="FCHardware: $fcmodels" fi if [ "$fcinterfaces" ]; then hw_fcinterfaces="FCWWPN: $fcinterfaces" fi if [ "$nameservers" ]; then hw_nameservers="DNS: $nameservers" fi if [ "$search" ]; then hw_search="DNSSearch: $search" fi if [ "$ipv4" ]; then hw_ipv4="IPv4: $ipv4" fi if [ "$ipv4dnsname" ]; then hw_ipv4dnsname="IPv4DNSName: $ipv4dnsname" fi if [ "$ipv6dnsname" ]; then hw_ipv6dnsname="IPv6DNSName: $ipv6dnsname" fi if [ "$ipv6" ]; then hw_ipv6="IPv6: $ipv6" fi if [ "$hwaddr" ]; then hw_addr="MAC: $hwaddr" fi if [ "$dhcp" ]; then hw_dhcp="DHCP: yes" else hw_dhcp="DHCP: no" fi if [ "$netmask" ]; then netmask=`hexoctet_todec "$netmask"` hw_netmask="NetMaskv4: $netmask" fi if [ "$broadcast" ]; then hw_broadcast="Broadcastv4: $broadcast" fi if [ "$mtu" ]; then hw_mtu="MTU: $mtu" fi if [ "$status" ]; then hw_status="Status: $status" fi if [ "$primdev" ]; then hw_dev="PrimDev: $primdev" fi if [ "$gateway" ]; then hw_gateway="Gatewayv4: $gateway" fi if [ "$nets" ]; then hw_nets="Devices: $nets" fi if [ "$netsalive" ]; then hw_alivenets="UpDevices: $netsalive" fi if [ "$speed" ]; then hw_netspeed="Speed: $speed" fi if [ "$duplex" ]; then hw_netduplex="Duplex: $duplex" fi if [ "$autoneg" ]; then hw_autoneg="AutoNeg: $autoneg" fi if [ "$port" ]; then hw_port="Port: $port" fi if [ "$hwvpn" ]; then hw_vpn="VPN: Enabled" fi if [ "$hwvpngate" ]; then hw_vpngw="VPNGateway: $hwvpngate" fi if [ "$hwvpndev" ]; then hw_vpndev="VPNDev: $hwvpndev" fi if [ "$hwvpnaddr" ]; then hw_vpnaddr="VPNMAC: $hwvpnaddr" fi if [ "$devhardware" ]; then hw_hardware="Hardware: $devhardware" fi if [ "$devvendor" ]; then hw_vendor="Vendor: $devvendor" fi dump_hw_vars Net # wiki output /sbin/ifconfig -a | sed 's/^/ /' echo "$speedout" | sed 's/^/ /' echo "" echo "$fcinfoout" | sed 's/^/ /' } hw_sunos_memory() { do_banner Memory Memory memsize="" freeinfo=`prtconf | head` # Big assumption that this always reports in Megabytes meg=`echo "$freeinfo" | sed -n 's/^[ ]*Memory size:[ ]*\([0-9][0-9]*\).*/\1/p'` l=`expr "$meg" : '.*'` if [ "$l" -ge 4 ]; then gig=`echo "$meg" | awk '{printf("%.2f", ($0/1024))}'` memsize="${gig}G" memcat=`memorycat gig $gig` else memsize="${meg}M" memcat=`memorycat meg $meg` fi if [ -x /usr/sbin/smbios ]; then smbiosout=`/usr/sbin/smbios 2>/dev/null` if [ "$smbiosout" ]; then memslots=`echo "$smbiosout" | nawk ' BEGIN { memdev=0 print ""; print "||! Size ||! Location ||! Speed ||! Type ||"; } / SMB_TYPE_MEMDEVICE / { memdev=1; next; } memdev && $1 == "Size:" { size=$2; $1=""; origsize=$0; stype="Bytes" if (size > 1024) { size=size / 1024; stype="KB"; if (size > 1024) { size=size / 1024; stype="MB"; if (size > 1024) { size=size / 1024; stype="GB"; } } } if (!size) size=origsize; else size=size" "stype; next; } memdev && $1 == "Speed:" { $1=""; speed=$0; next; } memdev && $1 == "Location" && $2 == "Tag:" { $1=""; $2=""; location=$0; next; } memdev && $1 == "Memory" && $2 == "Type:" { $1=""; $2=""; type=$0; next; } /^[^ ]/ { if (memdev && size != "") { print "||" size " ||" location " ||" speed " ||" type " ||"; size=""; location=""; speed=""; type=""; } memdev=0; next; } END { if (memdev) { print "||" size "||" location "||" speed "||"; } }'` fi elif [ -x /usr/local/sbin/dmidecode ]; then dmidecodeout=`/usr/local/sbin/dmidecode` memslots=`echo "$dmidecodeout" | nawk ' BEGIN { memdev=0; print ""; print "||! Size ||! Location ||! Speed ||! Type ||"; } /^[ ]*Memory Device/ { memdev=1; next; } /^[^ ]/ { if (memdev && size != "") { print "||" size " ||" location " ||" speed " ||" type " ||"; size=""; location=""; speed=""; type=""; } memdev=0; next; } memdev && $1 == "Size:" { $1=""; size=$0; next; } memdev && $1 == "Locator:" { $1=""; location=$0; next; } memdev && $1 == "Speed:" { $1=""; speed=$0; next; } memdev && $1 == "Type:" { $1=""; type=$0; next; } END { if (memdev) { print "||" size "||" location "||" speed "||"; } } '` fi if [ "$memcat" ]; then hw_class="Class: $memcat" fi if [ "$memsize" ]; then hw_size="Size: $memsize" fi if [ "$memslots" ]; then empty=`echo "$memslots" | egrep 'Not Populated|No Module' | wc -l` hw_empty="EmptySockets: $empty" fi dump_hw_vars Mem # wiki output echo " $memsize" if [ "$memslots" ]; then echo "$memslots" fi echo "" echo "[[!${memcat}]]" } hw_sunos_cpuinfo() { do_banner CPU "CPU Information" # How many physical processors do we have... pprocs=`psrinfo -p 2>/dev/null` if [ ! "$pprocs" ]; then pprocs=`uname -X | grep NumCPU | awk '{print $NF}' 2>/dev/null` fi # How many virtual processors do we have... lprocs=`psrinfo | wc -l 2>/dev/null` cpucores=`expr $lprocs / $pprocs` # What type of CPU is it... manufacturer="" cputype=`psrinfo -p -v 0 2>/dev/null| sed -n '3p'` if [ ! "$cputype" ]; then model=`uname -i` if [ -x /usr/platform/$model/sbin/prtdiag ]; then # prtdiag sometimes never returns, wait 5 seconds and kill it prtdiagout=`(/usr/platform/$model/sbin/prtdiag & pid=$!; sleep 5; kill $pid)` t=`echo "$prtdiagout" | sed -n 's/System Configuration:.*(\([^)][^)]*\)[)][^(]*/\1/p' 2>/dev/null` cputype=`echo "$t" | sed -e 's/^[0-9][0-9]* X //' \ -e 's/[0-9][0-9]*[ ]*M[Hh]z//' 2>/dev/null` fi fi if [ ! "$cputype" ]; then cputype=`psrinfo -p -v 2>/dev/null | grep clock | head -1 | awk '{print $1}' 2>/dev/null` fi if [ ! "$cputype" ]; then cputype=`psrinfo -p -v 2>/dev/null | sed -n 's/The \([^ ][^ ]*\) physical processor.*/\1/p' | head -1` fi if [ ! "$cputype" ]; then dmicpu=`dmiout cpu` if [ "$dmicpu" ]; then manufacturer=`echo "$dmicpu" | sed -n 's/ Manufacturer: \(.*\)/\1/p' | head -1` family=`echo "$dmicpu" | sed -n 's/ Family: \(.*\)/\1/p' | head -1` fsb=`echo "$dmicpu" | sed -n 's/ External Clock: \(.*\)/\1/p' | head -1` cur_speed=`echo "$dmicpu" | sed -n 's/ Current Speed: \(.*\)/\1/p' | head -1` cputype="$manufacturer $family $cur_speed ($fsb FSB)" else cputype=`prtconf | sed -n 's/^[ ]*SUNW,\([^ ]*SPARC[^ ]*\).*/\1/p' | head -1` if [ ! "$cputype" ]; then cputype=`psrinfo -v | sed -n 's/The \([^ ][^ ]*\) processor.*/\1/p' | head -1` fi if [ ! "$cputype" ]; then cputype="unknown" fi fi fi # What speed is the cpu... cpu_speed=`psrinfo -v | sed -n 's/.* operates at \([0-9][0-9]*\)[ ]*M[Hh]z.*/\1/p' | head -1` if [ ! "$cpu_speed" ]; then cpu_speed="unknown" fi # What cpu vendor type... pid=`psrinfo -p -v 2>/dev/null | sed -n 's/^.*[^A-Za-z]\([A-Za-z][A-Za-z]*\) family.*/\1/p' | sort -u` if [ ! "$pid" ]; then if [ "$manufacturer" = "Intel" ]; then pid="GenuineIntel" else pid=`uname -p` fi fi # what cpu type id.... cpu_id=`uname -m` # what/how much cache... # can only do this on x86, and only with dmidecode dmicache=`dmiout cache` if [ "$dmicache" ]; then cpu_cache=`echo "$dmicache" | sed -n 's/ Installed Size: \(.*\)/\1/p' | head -1` else cpu_cache="" fi # Get CPU core ids... core_ids=`psrinfo -p -v 2>/dev/null | grep 'virtual processor' | sed 's/.* [(]\([^)][^)]*\)[)]/\1/'` proc_count=`echo "$core_ids" | wc -l` if [ "$core_ids" -a "$proc_count" -ne "$pprocs" ]; then core_ids="unknown" fi # Calculate cores per processor cpucores=`expr $lprocs / $pprocs 2>&1` # Correct case on cputype and pid cpu=`cpucat "$pid" "$cputype"` pid=`echo "$cpu" | awk '{print $1}'` cputype=`echo "$cpu" | awk '{print $2}'` # Correct case on arch parch=`upperfirst "$cpu_id"` if [ "$parch" ]; then hw_arch="Arch: $parch" fi if [ "$cpucores" ]; then hw_cpucores="PCores: $cpucores" fi if [ "$pprocs" ]; then hw_pprocs="PNumber: $pprocs" fi if [ "$lprocs" ]; then hw_lprocs="LNumber: $lprocs" fi if [ "$cpu_cache" ]; then hw_cache="Cache: $cpu_cache" fi if [ "$cputype" ]; then hw_subclass="SubClass: $cputype" fi if [ "$pid" ]; then hw_class="Class: $pid" fi if [ "$cpu_speed" ]; then hw_freq="Freq: $cpu_speed" fi dump_hw_vars CPU # wiki output echo "||! # ||! Vendor ||! Type ||! Speed ||! Cache ||! Id ||! Cores ||" cpu_num=0 while [ $cpu_num -lt $pprocs ]; do if [ "$core_ids" -a "$core_ids" != "unknown" ]; then cpu_line_num=`expr $cpu_num + 1` core_id=`echo "$core_ids" | sed -n "${cpu_line_num}p"` # core_id could be a range, e.g. 0-31 core_start=`echo "$core_id" | sed -n 's/\([0-9][0-9]*\)-[0-9].*/\1/p'` if [ "$core_start" ]; then core_end=`echo "$core_id" | sed -n 's/[0-9][0-9]*-\([0-9][0-9]*\)/\1/p'` if [ ! "$core_end" ]; then core_ids="unknown" continue fi core_num=$core_start while [ $core_num -le $core_end ]; do echo "|| $core_num || $pid || $cputype || $cpu_speed || ${cpu_cache:=Unknown} || $cpu_id || $core_id ||" core_num=`expr $core_num + 1` done else # core_id should be comma separated list e.g. 0 or 0,16 core_list=`echo "$core_id" | tr ',' ' '` core_count=`echo "$core_list" | wc -w` if [ $core_count -lt $cpucores ]; then # Doesn't happen often, but some v240's get this wrong core_num=0 while [ $core_num -lt $cpucores ]; do echo "|| $core_num || $pid || $cputype || $cpu_speed || ${cpu_cache:=Unknown} || $cpu_id || $core_id ||" core_num=`expr $core_num + 1` done else for core_num in $core_list; do echo "|| $core_num || $pid || $cputype || $cpu_speed || ${cpu_cache:=Unknown} || $cpu_id || $core_id ||" done fi fi else echo "|| $cpu_num || $pid || $cputype || $cpu_speed || ${cpu_cache:=Unknown} || $cpu_id || NA ||" fi cpu_num=`expr $cpu_num + 1` done echo "" echo "[[!$pid]][[!$cputype]]" echo "[[!$parch]]" } hw_sunos_fs() { do_banner DiskFs "Disk File Systems" out=`/usr/xpg4/bin/df -l -P 2>/dev/null` if [ ! "$out" ]; then out=`df` fi echo "$out" | sed -e '1s/[Mm]ounted on/Mounted-On/' -e '1s/[ ][ ]*/ ||!/g' -e '1s/^/||!/' -e '2,$s/[ ][ ]*/ ||/g' -e '2,$s/^/||/' -e '2,$s/$/ ||/' if [ -x /usr/sbin/metastat ]; then metastatout=`/usr/sbin/metastat -p 2>/dev/null` if [ "$metastatout" ]; then echo "" echo "!!! Solaris SVM/Solstice DiskSuite Info" echo "$metastatout" | sed -e 's/ -m / is a mirror containing /' \ -e 's/ \([0-9]\) \([0-9]\) / concat of \1 disk(s) \2 stripe(s) from /' \ -e 's/ -p / is a soft partition of /' \ -e 's/ -o / offset /g' \ -e 's/ -b / blocks /g' -e 's/^/ /' fi fi if [ -x /usr/sbin/zfs -a -x /usr/sbin/zpool ]; then zpoolout=`/usr/sbin/zpool list 2>/dev/null` if [ "$zpoolout" ]; then echo "" echo "!!! Zpool Info" echo "$zpoolout" | sed 's/^/ /' fi zfsout=`/usr/sbin/zfs list 2>/dev/null` if [ "$zfsout" ]; then echo "" echo "!!! ZFS Info" echo "$zfsout" | sed 's/^/ /' fi fi #d0 -m d10 d20 1 #d10 1 1 c1t0d0s0 #d20 1 1 c1t3d0s0 #d1 -m d11 d21 1 #d11 1 1 c1t0d0s6 #d21 1 1 c1t3d0s6 #d4 2 1 c1t1d0s0 \ # 1 c1t2d0s0 #d11 -p d10 -o 1 -b 1024000 #d12 -p d10 -o 1024002 -b 7168000 #d13 -p d10 -o 8192003 -b 12697600 #d14 -p d10 -o 20889604 -b 1024000 #d10 1 1 c0t0d0s3 #d21 -p d20 -o 1 -b 12288000 -o 36864004 -b 20480000 #d22 -p d20 -o 12288002 -b 12288000 -o 57344005 -b 20480000 #d23 -p d20 -o 24576003 -b 12288000 -o 77824006 -b 20480000 #d20 1 1 c0t2d0s0 } hw_sunos_disks() { do_banner Disks "Disks" if [ -x /usr/bin/iostat ]; then iostatout=`iostat -En 2>/dev/null` fi if [ "$iostatout" ]; then iostatflatout=`echo "$iostatout" | awk ' /^[^A-Z]/ { dev=$1; } { if (dev != olddev) { if (olddev != "") print devline; olddev=dev; devline=$0; } else { devline=devline " " $0; } } END { if (devline != "") print devline; }' | sed -e 's/\([a-z]\) \([A-Z]\)/\1-\2/g' \ -e 's/\([^ ]\)[ ][ ]*\([A-Z][a-z]\)/\1,\2/g'` fi if [ "$iostatflatout" ]; then iotable=`echo "$iostatflatout" | while read flatline; do unset device vendor model rev serial sizeb size psize devinfo=\`echo "$flatline" | tr ',' '\012'\` device=\`echo "$devinfo" | head -1\` vendor=\`echo "$devinfo" | grep '^Vendor:' | cut -f2 -d:\` model=\`echo "$devinfo" | grep '^Model:' | cut -f2 -d:\` if [ ! "$model" ]; then model=\`echo "$devinfo" | grep '^Product:' | cut -f2 -d:\` fi rev=\`echo "$devinfo" | grep '^Revision:' | cut -f2 -d:\` serial=\`echo "$devinfo" | grep '^Serial-No:' | cut -f2 -d:\` sizeb=\`echo "$devinfo" | grep '^Size:' | sed -n 's/.*[<]\([0-9][0-9]*\).*/\1/p'\` if [ "$sizeb" ]; then size=\`expr $sizeb / 512\` psize=\`echo "$devinfo" | grep '^Size:' | cut -f2 -d: | awk '{print $1}'\` fi echo "$device $vendor $model $rev $serial $psize $size" done` fi blockdevs=`echo "$iotable" | cut -f1 -d' ' | sed 's/^$/-/' | tr '\012' ' '` devvendors=`echo "$iotable" | cut -f2 -d' ' | sed 's/^$/-/' |tr '\012' ' '` devmodels=`echo "$iotable" | cut -f3 -d' ' | sed 's/^$/-/' |tr '\012' ' '` devrevs=`echo "$iotable" | cut -f4 -d' ' | sed 's/^$/-/' |tr '\012' ' '` devserials=`echo "$iotable" | cut -f5 -d' ' | sed 's/^$/-/' |tr '\012' ' '` devsizes=`echo "$iotable" | cut -f7 -d' ' | sed 's/^$/-/' |tr '\012' ' '` if [ "$devserials" ]; then hw_serials="Serials: $devserials" fi if [ "$devclasses" ]; then hw_classes="Types: $devclasses" fi if [ "$devsizes" ]; then hw_sizes="Sizes: $devsizes" fi if [ "$devraids" ]; then hw_raids="RAID: $devraids" fi if [ "$devrevs" ]; then hw_revs="Revs: $devrevs" fi if [ "$devvendors" ]; then hw_vendors="Vendors: $devvendors" fi if [ "$devmodels" ]; then hw_models="Models: $devmodels" fi if [ "$blockdevs" ]; then hw_devs="Devices: $blockdevs" fi dump_hw_vars Disk # Wiki output echo "" echo "||!Device ||!Vendor ||!Model ||!Revision ||!Serial ||!Size ||" echo "$iotable" | cut -f1-6 -d' ' | sed -e 's/^/||/' -e 's/ / ||/g' -e 's/$/ ||/' } hw_sunos_software() { do_banner Software "Software" pkginfo -l | nawk ' BEGIN { printf("||!Name ||!Version ||!Arch ||!Date ||!Description ||\n"); } /^[ ]*PKGINST:/ { i=index($0,":"); pkginst=substr($0,(i+1)); } /^[ ]*NAME:/ { i=index($0,":"); name=substr($0,(i+1)); gsub(" ","_",name); } /^[ ]*ARCH:/ { i=index($0,":"); arch=substr($0,(i+1)); } /^[ ]*VERSION:/ { i=index($0,":"); version=substr($0,(i+1)); } /^[ ]*DESC:/ { i=index($0,":"); desc=substr($0,(i+1)); } /^[ ]*INSTDATE:/ { i=index($0,":"); instdate=substr($0,(i+1)); gsub(" ","_",instdate); } /^$/ { if (name != "") { printf("||%s ||%s ||%s ||%s ||%s ||\n",pkginst,version,arch,instdate,name); } name=""; } END { if (name != "") { printf("||%s ||%s ||%s ||%s ||%s ||\n",pkginst,version,arch,instdate,name); } }' | sed 's/||[ _]*/||/g' } hw_sunos_help() { echo "Options: hostname os memory cpuinfo interfaces fs disks" } if [ $# -eq 0 ]; then if [ "$HW_CMD" ]; then do_hw "$os" $HW_CMD else all "$os" fi else do_hw "$os" $* fi