ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux 系统健康巡检脚本

Linux 系统健康巡检脚本

原创 Linux操作系统 作者:dodba 时间:2011-03-09 10:29:42 0 删除 编辑
客户应用系统服务器要做健康检查,操作系统为Red Hat Enterprise Linux 5.6,数据库为oracle 10g,写了如下shell脚本:
  1. #!/bin/bash
  2. echo "You are logged in as `whoami`";
  3. if [ `whoami` != root ]; then
  4. echo "Must be logged on as root to run this script."
  5. exit
  6. fi
  7. CHECK_DATE=`date +%F`
  8. echo "Running script. at `date`"
  9. CHECK_REPORT_PATH=/tmp/getinfo
  10. ls -d $CHECK_REPORT_PATH
  11. if [ $? -gt 0 ]
  12. then
  13. mkdir $CHECK_REPORT_PATH
  14. fi
  15. chmod -R 777 $CHECK_REPORT_PATH
  16. CURRENT_DIR=`pwd`
  17. echo "#################### Check Start ####################"
  18. HOST=`hostname`
  19. echo "********Hostname Check**********" >$CHECK_REPORT_PATH/Report_$CHECK_DATE
  20. echo "Hostname is $HOSTNAME" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  21. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  22. #系统版本检查
  23. echo "********OS Level**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  24. uname -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  25. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  26. #系统日志检查
  27. echo "********System log*******" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  28. cat /var/log/messages >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  29. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  30. #文件系统检查
  31. echo "********File System**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  32. df -h >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  33. echo "over 75%" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  34. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  35. df -h |grep '[7-9][5-9]%'>>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  36. #网络地址配置信息
  37. echo "********System /etc/hosts********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  38. cat /etc/hosts >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  39. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  40. #查看内存使用情况
  41. echo "**********mem check************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  42. free >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  43. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  44. vmstat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  45. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  46. #查看磁盘读写情况
  47. echo "********io check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  48. iostat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  49. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  50. #网络检查
  51. echo "********network route check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  52. netstat -rn >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  53. echo "********network check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  54. ifconfig -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  55. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  56. #环境变量检查
  57. echo "********env info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  58. env >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  59. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  60. #用户组检查
  61. echo "********group info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  62. cat /etc/group >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  63. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  64. #用户密码检查
  65. echo "********user info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  66. cat /etc/passwd >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  67. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  68. #检查操作系统kernel信息
  69. echo "********System kernel info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  70. su - root -c $CURRENT_DIR/check_kernel.sh >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  71. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  72. #检查操作系统定时任务
  73. echo "********System crontab info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  74. crontab -l >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  75. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  76. #检查系统裸设备属主
  77. echo "******** RAW****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  78. ls -l /dev/sd* >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  79. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  80. #检查服务器上运行的数据库信息
  81. echo "********get oracle info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  82. Instance=`ps -ef|grep -v grep|grep oracle|awk '{print $1}'`
  83. for i in ${Instance}
  84. do
  85. su - $i -c $CHECK_REPORT_PATH/getdbinfo.sh
  86. done
  87. echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
  88. echo "#################### Check End! ####################"

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25369863/viewspace-688785/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-02-12

  • 博文量
    25
  • 访问量
    76688