背景

需要检查系统环境,是否能复现POC,不能复现的环境进行提示。
为了对客户友好的展示性:根据输入的字符串,将拆分的复现步骤的命令,逐一实行并打印有必要的提示。

已放弃

因为还需要考虑其他同事的代码习惯,Shell不是一个比较容易上手的语言,Python用户多,大家多少都有了解或者其他同事能帮忙改的。所以改为Python。
Python的问题就是Python2和Python3的些微不同,还有Linux环境上安装第三方库可能有点麻烦。

Shell代码

  1. echo -e "-------------------------------System Information----------------------------"
  2. echo -e "Hostname:\t\t\t"`hostname`
  3. echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
  4. echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
  5. echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
  6. echo -e "Version:\t\t\t"`cat /sys/class/dmi/id/product_version`
  7. echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
  8. echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
  9. echo -e "Operating System:\t\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
  10. echo -e "Kernel:\t\t\t"`uname -r`
  11. echo -e "Architecture:\t\t"`arch`
  12. echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
  13. echo -e "Active User:\t\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
  14. echo -e "System Main IP:\t\t"`hostname -I`
  15. echo ""
  16. echo -e "-------------------------------CPU/Memory Usage------------------------------"
  17. echo -e "Memory Usage:\t\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
  18. echo -e "Swap Usage:\t\t\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
  19. 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`
  20. echo ""
  21. echo -e "----------------------------------Check List----------------------------------"
  22. echo -e "Check1:"
  23. echo -e "Check2:"
  24. echo -e "Check3:"
  25. echo -e "Check4:"
  26. echo ""
  27. echo -e "---------------------------------Step Choice---------------------------------"
  28. echo -e "Step1:启动"
  29. echo -e "Step2:步骤二"
  30. echo -e "Step3:步骤三"
  31. echo -e "Step4:步骤四"
  32. read -p "Please Input Step Number: " nStep
  33. read -p "输入a、b、c中的一个:" Get
  34. case $Get in
  35. a)
  36. echo "输入的是a"
  37. ;;
  38. b)
  39. echo "输入的是b"
  40. ;;
  41. c)
  42. echo "输入的是c"
  43. ;;
  44. esac
  45. while $nStep
  46. if $nStep -ne ""
  47. then echo $nStep
  48. if $nStep -eq "1"
  49. then echo "1111111111"
  50. else echo "输入其他"
  51. fi
  52. else echo "无输入"
  53. fi
  54. echo ""
  55. echo -e "-------------------------------Disk Usage >80%-------------------------------"
  56. df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
  57. echo ""
  58. echo -e "-------------------------------For WWN Details-------------------------------"
  59. vserver=$(lscpu | grep Hypervisor | wc -l)
  60. if [ $vserver -gt 0 ]
  61. then
  62. echo "$(hostname) is a VM"
  63. else
  64. cat /sys/class/fc_host/host?/port_name
  65. fi
  66. echo ""
  67. echo -e "-------------------------------Oracle DB Instances---------------------------"
  68. if id oracle >/dev/null 2>&1
  69. then
  70. bin/ps -ef | grep pmon
  71. else
  72. echo "oracle user does not exist on $(hostname)"
  73. fi
  74. echo ""
  75. if ( $(cat /etc/*-release | grep -w "Oracle|Red Hat|CentOS|Fedora" | wc -l) > 0 )
  76. then
  77. echo -e "-------------------------------Package Updates-------------------------------"
  78. yum updateinfo summary | grep 'Security|Bugfix|Enhancement'
  79. echo -e "-----------------------------------------------------------------------------"
  80. else
  81. echo -e "-------------------------------Package Updates-------------------------------"
  82. cat /var/lib/update-notifier/updates-available
  83. fi
  84. echo ""
  85. echo -e "----------------------------------Finished-----------------------------------"