背景
需要检查系统环境,是否能复现POC,不能复现的环境进行提示。
为了对客户友好的展示性:根据输入的字符串,将拆分的复现步骤的命令,逐一实行并打印有必要的提示。
已放弃
因为还需要考虑其他同事的代码习惯,Shell不是一个比较容易上手的语言,Python用户多,大家多少都有了解或者其他同事能帮忙改的。所以改为Python。
Python的问题就是Python2和Python3的些微不同,还有Linux环境上安装第三方库可能有点麻烦。
Shell代码
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "Swap Usage:\t\t\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Usage:\t\t\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1`
echo ""
echo -e "----------------------------------Check List----------------------------------"
echo -e "Check1:"
echo -e "Check2:"
echo -e "Check3:"
echo -e "Check4:"
echo ""
echo -e "---------------------------------Step Choice---------------------------------"
echo -e "Step1:启动"
echo -e "Step2:步骤二"
echo -e "Step3:步骤三"
echo -e "Step4:步骤四"
read -p "Please Input Step Number: " nStep
read -p "输入a、b、c中的一个:" Get
case $Get in
a)
echo "输入的是a"
;;
b)
echo "输入的是b"
;;
c)
echo "输入的是c"
;;
esac
while $nStep
if $nStep -ne ""
then echo $nStep
if $nStep -eq "1"
then echo "1111111111"
else echo "输入其他"
fi
else echo "无输入"
fi
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt 0 ]
then
echo "$(hostname) is a VM"
else
cat /sys/class/fc_host/host?/port_name
fi
echo ""
echo -e "-------------------------------Oracle DB Instances---------------------------"
if id oracle >/dev/null 2>&1
then
bin/ps -ef | grep pmon
else
echo "oracle user does not exist on $(hostname)"
fi
echo ""
if ( $(cat /etc/*-release | grep -w "Oracle|Red Hat|CentOS|Fedora" | wc -l) > 0 )
then
echo -e "-------------------------------Package Updates-------------------------------"
yum updateinfo summary | grep 'Security|Bugfix|Enhancement'
echo -e "-----------------------------------------------------------------------------"
else
echo -e "-------------------------------Package Updates-------------------------------"
cat /var/lib/update-notifier/updates-available
fi
echo ""
echo -e "----------------------------------Finished-----------------------------------"