Linux 系统健康巡检脚本
客户应用系统服务器要做健康检查,操作系统为Red Hat Enterprise Linux 5.6,数据库为oracle 10g,写了如下shell脚本: #!/bin/bash echo "You are logged in as `whoami`"; if [ `whoami` != root ]; then echo "Must be logged on as root to run this script." exit fi CHECK_DATE=`date +%F` echo "Running script. at `date`" CHECK_REPORT_PATH=/tmp/getinfo ls -d $CHECK_REPORT_PATH if [ $? -gt 0 ] then mkdir $CHECK_REPORT_PATH fi chmod -R 777 $CHECK_REPORT_PATH CURRENT_DIR=`pwd` echo "#################### Check Start ####################" HOST=`hostname` echo "********Hostname Check**********" >$CHECK_REPORT_PATH/Report_$CHECK_DATE echo "Hostname is $HOSTNAME" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #系统版本检查 echo "********OS Level**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE uname -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #系统日志检查 echo "********System log*******" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE cat /var/log/messages >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #文件系统检查 echo "********File System**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE df -h >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo "over 75%" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE df -h |grep '[7-9][5-9]%'>>$CHECK_REPORT_PATH/Report_$CHECK_DATE #网络地址配置信息 echo "********System /etc/hosts********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE cat /etc/hosts >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #查看内存使用情况 echo "**********mem check************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE free >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE vmstat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #查看磁盘读写情况 echo "********io check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE iostat >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #网络检查 echo "********network route check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE netstat -rn >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo "********network check**********" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE ifconfig -a >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #环境变量检查 echo "********env info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE env >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #用户组检查 echo "********group info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE cat /etc/group >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #用户密码检查 echo "********user info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE cat /etc/passwd >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #检查操作系统kernel信息 echo "********System kernel info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE su - root -c $CURRENT_DIR/check_kernel.sh >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #检查操作系统定时任务 echo "********System crontab info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE crontab -l >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #检查系统裸设备属主 echo "******** RAW****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE ls -l /dev/sd* >>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE #检查服务器上运行的数据库信息 echo "********get oracle info****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE Instance=`ps -ef|grep -v grep|grep oracle|awk '{print $1}'` for i in ${Instance} do su - $i -c $CHECK_REPORT_PATH/getdbinfo.sh done echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE echo "#################### Check End! ####################"
喜欢请赞赏一下啦^_^
微信赞赏
支付宝赞赏