博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux 系统健康巡检脚本
阅读量:5820 次
发布时间:2019-06-18

本文共 4775 字,大约阅读时间需要 15 分钟。

客户应用系统服务器要做健康检查,操作系统为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! ####################"

转载地址:http://imzdx.baihongyu.com/

你可能感兴趣的文章
ntpdate时间同步
查看>>
+++++++子域授权与编译安装(一)
查看>>
asp.net怎样在URL中使用中文、空格、特殊字符
查看>>
路由器发布服务器
查看>>
实现跨交换机VLAN间的通信
查看>>
jquery中的data-icon和data-role
查看>>
python例子
查看>>
环境变量(总结)
查看>>
ios之UILabel
查看>>
Java基础之String,StringBuilder,StringBuffer
查看>>
1月9日学习内容整理:爬虫基本原理
查看>>
安卓中数据库的搭建与使用
查看>>
AT3908 Two Integers
查看>>
渐变色文字
查看>>
C++ 0X 新特性实例(比较常用的) (转)
查看>>
node生成自定义命令(yargs/commander)
查看>>
各种非算法模板
查看>>
node-express项目的搭建并通过mongoose操作MongoDB实现增删改查分页排序(四)
查看>>
PIE.NET-SDK插件式二次开发文档
查看>>
如何创建Servlet
查看>>