반응형
#!/bin/bash
source ~/.bash_profile
###########################################################################################
######## require locfg.pl, [iLO_*].xml ###########
######## locfg.pl and Get_Network.xml same path and in home_dir ###########
######## perl locfg.pl -s [iLO IP] -f [Use config file] -u [User] -p [Password] ###########
###########################################################################################
date=`date +%Y%d%m%H`
home_dir=health_check
work_dir=health_check/$date
mkdir -p $work_dir
hp_ilo_user="******"
hp_ilo_pass="******"
echo "================================="
echo "Please typed count"
echo "================================="
echo "1. Target Time Check"
echo "2. Read list file and time check"
echo "3. NTP(SNTP server) check"
echo "4. Hardware Check"
read count
echo [$count]
if [[ $count == 1 ]]
then
cat $home_dir/ilo_check.list
echo "Please typed IP Address"
read ipaddr
server_ilo=`cat $home_dir/ilo_check.list | grep $ipaddr | awk -F"," '{print $2}'`
perl locfg.pl -s $ipaddr -f Get_Network.xml -u $hp_ilo_user -p $hp_ilo_pass | grep "TIMEZONE" | awk -F'"' '{print $2}' > $work_dir/temp.txt
timez=`cat $work_dir/temp.txt`
date_iloo=$(sshpass -phpinvent ssh -o StrictHostKeyChecking=no -o LogLevel=quiet hpadmin@$ipaddr -p22 date | sed -e "s/
//g" | grep -Ev "date|^$")
time_iloo=$(sshpass -phpinvent ssh -o StrictHostKeyChecking=no -o LogLevel=quiet hpadmin@$ipaddr -p22 time | sed -e "s/
//g" | grep -Ev "time|^$")
printf "%80s | %20s | %10s | %15s | %15s \n" Time_zone Date Time Name iLOIP
echo "=================================================================================================================================================================="
printf "%80s | %20s | %10s | %15s | %15s \n" "$timez" "$date_iloo" "$time_iloo" $server_ilo $ipaddr
elif [[ $count == 2 ]]
then
printf "%80s | %20s | %10s | %15s | %15s \n" Time_zone Date Time Name iLOIP
echo "=================================================================================================================================================================="
for ip in `cat $home_dir/ilo_check.list`
do
health_check_ip=`cat $home_dir/ilo_check.list | awk -F"," '{print $1}' <<< $ip`
server_name=`cat $home_dir/ilo_check.list | awk -F"," '{print $2}' <<< $ip`
perl locfg.pl -s $health_check_ip -f Get_Network.xml -u $hp_ilo_user -p $hp_ilo_pass | grep "TIMEZONE" | awk -F'"' '{print $2}' > $work_dir/temp.txt
time=`cat $work_dir/temp.txt`
date_ilo=$(sshpass -phpinvent ssh -o StrictHostKeyChecking=no -o LogLevel=quiet hpadmin@$health_check_ip -p22 date | sed -e "s/
//g" | grep -Ev "date|^$")
time_ilo=$(sshpass -phpinvent ssh -o StrictHostKeyChecking=no -o LogLevel=quiet hpadmin@$health_check_ip -p22 time | sed -e "s/
//g" | grep -Ev "time|^$")
printf "%80s | %20s | %10s | %15s | %15s \n" "$time" "$date_ilo" "$time_ilo" $server_name $health_check_ip
done
elif [[ $count == 3 ]]
then
echo "==============================================================================================="
printf "%30s | %15s | %30s \n" ServerName iLOIP NTP_set
echo "==============================================================================================="
for ntp in `cat $home_dir/ilo_check.list`
do
ntp_check_ip=`cat $home_dir/ilo_check.list | awk -F"," '{print $1}' <<< $ntp`
server_ilo_ntp=`cat $home_dir/ilo_check.list | awk -F"," '{print $2}' <<< $ntp`
ntp_check=`perl locfg.pl -s $ntp_check_ip -f Get_Network.xml -u $hp_ilo_user -p $hp_ilo_pass | grep -i sntp_server | awk -F'"' '{print $2}'`
if [[ -z $ntp_check ]]
then
ntp_check="SNTP_SERVER is not set"
elif [[ -n $ntp_check ]]
then
$ntp_check
fi
printf "%30s | %15s | %30s \n" $server_ilo_ntp $ntp_check_ip "$ntp_check"
done
elif [[ $count == 4 ]]
then
echo "==================================================================================================================================="
printf "%21s | %15s | %8s | %8s | %8s | %8s | %8s | %8s | %8s | \n" Server_Name iLO_IP FAN TEMP POWER BATTERY PROCESSOR MEMORY STORAGE
echo "==================================================================================================================================="
for ip2 in `cat $home_dir/ilo_check.list`
do
health_check_ip2=`cat $home_dir/ilo_check.list | awk -F"," '{print $1}' <<< $ip2`
server_name2=`cat $home_dir/ilo_check.list | awk -F"," '{print $2}' <<< $ip2`
perl locfg.pl -s $health_check_ip2 -f Get_EmHealth.xml -u $hp_ilo_user -p $hp_ilo_pass > $work_dir/ilo_check.txt
cat $work_dir/ilo_check.txt | egrep "FANS STATUS|TEMPERATURE STATUS|POWER_SUPPLIES STATUS|BATTERY STATUS|PROCESSOR STATUS|MEMORY STATUS|STORAGE STATUS" | sed 's/[^a-z,A-Z,0-9,=]//g' | awk -F"=" '{print $2}' | xargs echo > $home_dir/health.txt
FAN=`awk '{print $1}' $home_dir/health.txt`
TEMP=`awk '{print $2}' $home_dir/health.txt`
POWER=`awk '{print $3}' $home_dir/health.txt`
BATTERY=`awk '{print $4}' $home_dir/health.txt`
PROCESSOR=`awk '{print $5}' $home_dir/health.txt`
MEMORY=`awk '{print $6}' $home_dir/health.txt`
STORAGE=`awk '{print $7}' $home_dir/health.txt`
printf "%21s | %15s | %8s | %8s | %8s | %8s | %8s | %8s | %8s | \n" $server_name2 $health_check_ip2 $FAN $TEMP $POWER $BATTERY $PROCESSOR $MEMORY $STORAGE #Sensors threshold temperature is not same
done
else
echo "Typed number is not defined"
echo "Close shell"
rm -rf $work_dir
exit
fi
rm -rf $work_dir
여러 서버가 전부 시간대가 맞지 않아서 아래 내용 추가하여 사용 중입니다~
NTP Check
Area Time
HW : ilo ip 추가, Smart Storage Battery 감시 추가
반응형
'Command & Development > Shell Script' 카테고리의 다른 글
[Shell Script] List 내 서버 접속 / 정보 확인 (0) | 2024.06.13 |
---|---|
[ShellScript] DB, NFS Backup check (0) | 2023.07.18 |
[ShellScript] Avamar Backup Check (0) | 2023.07.17 |
[Shell Script] iLO Health Check Script (0) | 2023.02.21 |
[Shell Script] Linux 설치 후 초기 설정 (0) | 2023.01.31 |