#!/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 "********Yum*******" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
history | grep yum && history | grep rpm >>$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
#检查操作系统定时任务
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 "********REBOOT****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
last | grep reboot && last | grep shutdown >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
#登录用户检查及远程登录
echo "********USER****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
who && who | wc -l >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
netstat -anp | grep 22 >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
#系统运行时间及平均负载
echo "********Uptime****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
uptime >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
#检查系统占用cpu,内存,磁盘io最大的进程
echo "********Dstat cpu****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
dstat -c -y -l --proc-count --top-cpu 2 3 >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
echo "********Dstat mem****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
dstat -g -l -m -s --top-mem 2 3 >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
echo "********Dstat io****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
dstat --top-io 2 3 >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
#进程总数
echo "********Dstat proc****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
dstat --proc-count 3 3 >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE
#检查selinux
echo "********SELINUX****************" >>$CHECK_REPORT_PATH/Report_$CHECK_DATE
getenforce >> $CHECK_REPORT_PATH/Report_$CHECK_DATE
echo -e "----------------------------------------------------\n">>$CHECK_REPORT_PATH/Report_$CHECK_DATE