Wednesday, 4 January 2012

A very ugly script to collect Red Hat servers information

In development. The idea is parsing the fields to create a comma separated file.


######### hostname
echo "\"`hostname -s`\";"

######### dominio
echo "\"`hostname -d`\";"

######### ip1
echo "\"`ip addr show|grep inet|grep -v inet6|grep -v 127.0.0.1|awk '{print $2}'|head -1`\";"

######### ip2
echo "\"`ip addr show|grep inet|grep -v inet6|grep -v 127.0.0.1|awk '{print $2}'|tail -1`\";"

######### ha net?
if [ -f /proc/net/bond/bonding ];
        then
                echo "\"si\";"
        else
                echo "\"no\";"
fi

######### tipo
if [ $(dmidecode|grep Manufacturer|head -1|awk '{print $2}') == "VMware," ];
        then
                echo "\"virtual\";"
        else
                echo "\"fisico\";"
fi

######### fabricante
echo "\"`dmidecode|grep Manufacturer|head -1|awk -F: '{print $2}'|sed -e 's/^[ \t]*//'`\";"

######### modelo
echo "\"`dmidecode |grep 'Product Name'|head -1|awk -F: '{print $NF}'|sed -e 's/^[ \t]*//'`\";"

######### serie
echo "\"`dmidecode |grep 'Serial Number'|head -1 |awk -F: '{print $NF}'|sed -e 's/^[ \t]*//'`\";"

######### bits arquitectura
echo "\"`dmidecode |grep 'Core Enabled' -n3|tail -1|awk '{print $2}'|awk -F- '{print $1}'|sed -e 's/^[ \t]*//'`\";"

######### tipo so
echo "\"`uname -s`\";"

######### so
echo "\"`lsb_release -i|awk '{print $3}'`\";"

######### version so
echo "\"`lsb_release -r|awk '{print $2}'`\";"

######### kernel
echo "\"`uname -r`\";"

######### bits so
if [ `uname -m` == "i686" ];
        then
                echo "\"32\";";
        else echo "\"64\";";
fi

######### ram (Mb)
echo "\"`free -m|grep Mem|awk '{print $2}'`\";"

######### swap
echo "\"`free -m|grep Swap|awk '{print $2}'`\";"

######### cpu
echo "\"`cat /proc/cpuinfo |grep 'model name'|head -1|awk -F: '{print $2}'`\";"

######### nucleos
echo "\"`cat /proc/cpuinfo |grep 'model name'|wc -l`\";"

######### hora
echo "\"`date`\";"

######### tipo hora
echo "\"`ps aux |grep ntp|grep -v grep  > /dev/null ; if [ $? == "0" ];then echo "ntp"; else echo "local"; fi`\";"

######### tz archivo
echo "\"`ls -l /etc/localtime| awk -F/ '{print $NF}'`\";"

######### tz date
echo "\"`date +%Z`\";"

######### srv. ntp
if [ `grep server /etc/ntp.conf |grep -v "#"|awk '{print $2}'|grep "165.182.219.198" > /dev/null; echo $?` == 0

];then
        if [ `grep server /etc/ntp.conf |grep -v "#"|awk '{print $2}'|wc -l` == 1 ]; then
                echo "ntp_server_ip";
        else
                echo "++ ntp_server_ip";
        fi;
else
        echo "not company";
fi

######### sync. ntp
if [ `ntpq -p>/dev/null; echo $?` == 0 ];
        then
                echo "\"ok\";";
        else echo "\"nok\";";
fi

######### ag. respaldo instalados
if [ `rpm -q TIVsm-BA->/dev/null;echo $?` == 0 ];
        then
                echo "\"tivoli\";";
        else
                if [ `rpm -q BABcmagt>/dev/null; echo $?` == 0 ];
                        then
                                echo "\"brightstor\";";
                        else
                                echo "\"no instalado\";";
                fi
fi

######### estado ag. respaldo
if [ `rpm -q TIVsm-BA->/dev/null;echo $?` == 0 ];
        then
                if [ "$(pidof dsmc)" ] && [ `netstat -putan |grep ":1501" > /dev/null;echo $?` == 0 ];
                        then
                                echo "\"ok\";";
                        else
                                echo "\"nok\";";
                fi
        else
                if [ `rpm -q BABcmagt>/dev/null; echo $?` == 0 ];
                        then
                                if [ "$(pidof caagentd)" ] && [ `netstat -putan |grep tcp|grep ":6051" > /dev/null;

echo $?` == 0 ];
                                        then
                                                echo "\"ok\";";
                                        else
                                                echo "\"nok\";";
                                fi
                fi
fi  

######### ag. monitoreo
if [ -f /etc/init.d/zabbix_agentd ];
        then
                echo "\"zabbix\";";
        else
                echo "\"no instalado\";";
fi

######### estado ag. monitoreo
if [ "$(pidof zabbix_agentd)" ];
        then
                echo "\"ok\";";
        else
                echo "\"nok\";";
fi

######### hd total
echo "\"`vgdisplay --units g|grep -v failed|grep 'VG Size'|awk '{print $(NF-1)}'|awk '{sum+=$1} END {print sum}'|

tail -1`\";"

######### hd asignado
echo "\"`vgdisplay --units g|grep -v failed|grep 'Alloc PE'|awk '{print $(NF-1)}'|awk '{sum+=$1} END {print sum}'|

tail -1`\";"

######### hd asignable
echo "\"`vgdisplay --units g|grep -v failed|grep 'Free  PE'|awk '{print $(NF-1)}'|awk '{sum+=$1} END {print sum}'|

tail -1`\";"

No comments:

Post a Comment