运维联盟俱乐部

 找回密码
 立即注册
查看: 1738|回复: 0

os_check_linux

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2022-3-31 09:36:34 | 显示全部楼层 |阅读模式
    --
    1. #!/bin/sh

    2. #USAGE    : collect linux os info
    3. #AUTHOR   : zhangyu
    4. #VERSION  : v1.0
    5. #MODIFIED : 2018 05 10  

    6. logdir=/tmp/ht/`date +%y%m%d`
    7. [ ! -d $logdir ] && mkdir -p $logdir&&chmod -R 777 $logdir
    8. echo "The output dir ${logdir} has been created successfully!"
    9. log=$logdir/os_info_`hostname`_`date +%y%m%d%H%M`
    10. index=1
    11.                                                                                                                                        
    12. # run this script use root
    13. [ $(id -u) -gt 0 ] && echo "please  run the script with root user! " && exit 1

    14. # sequential title for $log
    15. echo_title(){
    16.                 echo >> $log
    17.         echo ======================= `hostname`:${index}. $* >> $log
    18.         let index=$index+1
    19.         echo >> $log
    20. }

    21. # prompt of terminal
    22. echo_back(){
    23.   [ $(echo $SHELL|grep bash|wc -l) -eq 1 ]&&{
    24.         echo -n $*
    25. }||{
    26.         echo "$*\c"
    27. }
    28. }
    29. #check release ventor
    30. vendor=$(
    31.         if [ -e /etc/oracle-release ];then cat /etc/oracle-release|head -1
    32.         elif [ -e /etc/redhat-release ];then cat /etc/redhat-release|head -1
    33.         elif [ -e /etc/SuSE-release ];then cat /etc/SuSE-release|head -1
    34.         else echo "Other Release"
    35.         fi
    36. )

    37. #collect ip info
    38. ipaddr=$(
    39. for i in $(ip link | grep BROADCAST | awk -F: '{print $2}');
    40. do
    41. ip add show $i | grep -E "BROADCAST|global"| awk '{print $2}' | tr '\n' ' '
    42. echo
    43. done
    44. )

    45. #collect os base info
    46. base_info(){
    47. echo "OS TYPE     :$(uname -s -i)"
    48. echo "OS VENDOR   :${vendor}"
    49. echo "HOST NAME   :$(hostname)"
    50. echo "CHECK DATE  :$(date '+%y_%m_%d %H:%M:%S')"
    51. echo "UP TIME     :$(uptime| awk -F[,] '{print $1}'|sed 's/^ //')"
    52. echo "CPU MODE    :$(grep "model name" /proc/cpuinfo|sort -u |awk -F[:] '{print $2}'|sed 's/^ //')"
    53. echo "CPU COUNT   :$(grep "processor" /proc/cpuinfo|wc -l)"
    54. echo "PHY MEM PCT :$(free -m|grep Mem|awk '{print $2,$3,$4}') MB"
    55. echo "SWAP EMM PCT:$(free -m | grep Swap|awk '{print $2,$3,$4}') MB"
    56. echo "LOCALE      :$(locale|grep LANG|awk -F[=] '{print $2}')"
    57. echo "TIME ZONE   :$(date +%Z%z)"

    58. echo_title hostname info
    59. cat /etc/hosts|grep -v ^#|grep -v ^$

    60. echo_title memory nd swap info
    61. grep MemTotal /proc/meminfo
    62. grep SwapTotal /proc/meminfo
    63. echo
    64. free -m

    65. echo_title ip info
    66. echo "${ipaddr}"
    67. echo
    68. ifconfig -a

    69. echo_title usage nd mount info
    70. df -h
    71. echo
    72. lsblk

    73. echo_title user info
    74. cat /etc/shadow

    75. echo_title group info
    76. cat /etc/group

    77. echo_title firewall nd selinux info
    78. systemctl status firewalld
    79. service iptables status
    80. echo "selinux:`getenforce`"

    81. echo_title crontab info
    82. crontab -l>/dev/null 2>&1
    83. if [ $? -eq 0 ];then
    84.         crontab -l | grep -v ^$ | grep -v ^#
    85. fi

    86. echo_title sysctl info
    87. cat /etc/sysctl.conf| grep -v ^#|grep -v ^$

    88. echo_title security limits
    89. cat /etc/security/limits.conf| grep -v ^#|grep -v ^$
    90. grep -v ^# /etc/security/limits.d/*.conf|grep -v ^$

    91. echo_title processes tree
    92. pstree -a -A -c -l -n -p -u -U

    93. echo_title port info
    94. netstat -anlp|grep tcp|grep -E "ora|postgres|asm|mysql|maria|oninit|sybase|httpd"|grep -v tcp6

    95. echo_title vmstat info
    96. vmstat 2 10

    97. echo_title dmesg
    98. tail -100 /var/log/messages
    99. }

    100. echo_back Start to collecting information ...
    101. echo
    102. echo_title os base info
    103. base_info >> $log

    104. echo "OK!completed.see the log file:$log"
    复制代码




    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-5-7 03:00 , Processed in 0.062357 second(s), 30 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表