@@ -1,8 +1,8 @@
#!/bin/bash
# Inventory System
# Author: Carsten Schoene
-# $LastChangedDate: 2012-08-12 11:17:00 +0200 (Sun, 12 Aug 2012) $
-# $Rev: 1693 $
+# $LastChangedDate: 2012-08-12 12:42:39 +0200 (Sun, 12 Aug 2012) $
+# $Rev: 1694 $
#
# Default options (can be changed by inventory-system.conf)
DEBUG="yes"
@@ -38,6 +38,7 @@
date
modprobe
ipmitool
+getopt
"
# clean old logfile
@@ -82,83 +83,84 @@
# script usage
function usage {
echo "Usage: $0 [--help|--uuid|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]"
- echo -e "\t--help\tShows this help"
- echo -e "\t--uuid\tUUID of this system"
+ echo -e "\t--help\t\tShows this help"
+ echo -e "\t--uuid\t\tUUID of this system"
echo -e "\t--systemtype\tSystem image type"
echo -e "\t--serial\tSystem serial number (Service Tag)"
- echo -e "\t--cpu\tCPU type"
- echo -e "\t--mem\tAmount of memory installed in MB"
+ echo -e "\t--cpu\t\tCPU type"
+ echo -e "\t--mem\t\tAmount of memory installed in MB"
echo -e "\t--product\tSystem model"
- echo -e "\t--arch\tSystem architecture"
- echo -e "\t--os\tOS version installed"
+ echo -e "\t--arch\t\tSystem architecture"
+ echo -e "\t--os\t\tOS version installed"
echo -e "\t--kernel\tRunning kernel version"
echo -e "\t--mgmtmac\tIPMI management MAC address"
echo -e "\t--mgmtip\tIPMI management IP address"
+ exit
}
RUN_FUNCTIONS=""
-args=`getopt -a --long help,uuid,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"`
+args=`${GETOPT} -a -o h -l help,uuid,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"`
+if [ $? != 0 ] ; then
+ usage
+fi
+
eval set -- "$args"
for opt ; do
case "$opt" in
- --help)
+ -h|--help)
usage
- exit
;;
- --uuid)
+ -u|--uuid)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_uuid"
shift
;;
- --systemtype)
+ -t|--systemtype)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_type"
shift
;;
- --serial)
+ -s|--serial)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_serial"
shift
;;
- --cpu)
+ -c|--cpu)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_cpu"
shift
;;
- --mem)
+ -m|--mem)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_memory"
shift
;;
- --product)
+ -p|--product)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_productname"
shift
;;
- --arch)
+ -a|--arch)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_arch"
shift
;;
- --os)
+ -o|--os)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_os"
shift
;;
- --kernel)
+ -k|--kernel)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_kernelversion"
shift
;;
- --mgmtmac)
+ -g|--mgmtmac)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_mgmt_mac"
shift
;;
- --mgmtip)
+ -i|--mgmtip)
RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_mgmt_ip"
shift
;;
+ --)
+ shift
+ break
+ ;;
esac
done
-if [ -n "${FUN_FUNCTIONS}" ] ; then
- for FUNC in ${RUN_FUNCTIONS} ; do
- ${FUNC}
- done
- exit
-fi
-
# get unique system uuid
function get_system_uuid {
# newer systems have uuid integrated
@@ -474,13 +476,20 @@
}
###### now output system data ######
-if [ -n "`echo ${TARGETURL} | grep ^https`" ] ; then
- ${CURL} -s -k -d "`build_request`" ${TARGETURL} >/dev/null
+if [ -n "${RUN_FUNCTIONS}" ] ; then
+ for FUNC in ${RUN_FUNCTIONS} ; do
+ ${FUNC}
+ done
+ exit
else
- ${CURL} -s -d "`build_request`" ${TARGETURL} >/dev/null
-fi
-if [ $? != 0 ] ; then
- debug "Data upload failed!"
+ if [ -n "`echo ${TARGETURL} | grep ^https`" ] ; then
+ ${CURL} -s -k -d "`build_request`" ${TARGETURL} >/dev/null
+ else
+ ${CURL} -s -d "`build_request`" ${TARGETURL} >/dev/null
+ fi
+ if [ $? != 0 ] ; then
+ debug "Data upload failed!"
+ fi
+ mailalerts
fi
-mailalerts
|