vim inspection.sh
#!/bin/bash
echo "#############系统信息#############"
type=`uname`
version=`cat /etc/redhat-release`
kernel=`uname -a|awk '{print $3}'`
time=`date +%F_%T`
runningtime=`uptime|awk '{print $3}'|awk -F , '{print $1}'`
restarttime=`who -b |awk '{print $2,$3}'`
host=`hostname`
echo " 系统类型:$type"
echo " 系统版本:$version"
echo " 系统内核:$kernel"
echo " 当前时间:$time"
echo " 运行时间:$runningtime"
echo " 最后重启时间:$restarttime"
echo " 本机名称:$host"
echo "############# 网络信息#############"
shesi=`ifconfig |grep ens|awk -F : '{print $1}'`
for i in $shesi
do
wangluo=`ifconfig $i|awk '/netmask/{print $2}'`
echo " 本机IP:$shesi:$wangluo"
done
curl -I www.baidu.com &>/dev/null
if [ $? -eq 0 ];then
echo " 外网正在使用"
else
echo " 外网断开"
fi
echo "############# 硬件信息#############"
amount=`cat /proc/cpuinfo|awk -F : '/physical id/{print $2}'|sort|uniq|wc -l`
core=`grep "cpu cores" /proc/cpuinfo|sort|uniq|awk '{print $4}'`
model=`grep "model name" /proc/cpuinfo|sort|uniq|awk -F: '{print $2}'`
echo " CPU数量: $amount"
echo " CPU核心: $core"
echo " CPU型号:$model"
neicunz=`free -m|awk '/Mem/{print $2}'`
shenyu=`free -m|awk '/Mem/{print $7}'`
echo " 内存总容量: $neicunz MB"
echo "剩余内存容量: $shenyu MB"
zonglian=`df -m |grep -v "tmpfs"|sed '1d'|awk '{print $2}'`
swap=`free -m|awk '/Swap/{print $2}'`
zl=0
for i in $zonglian
do
zl=$(($zl+$i))
done
echo " 磁盘总容量:$((($zl+$swap)/1000)) GB"
yunlian=`df -m|sed '1d'|grep -v tmpfs|awk '{print $4}'`
yunswap=`free -m|awk '/Swap/{print $4}'`
yu=0
for i in $yunlian
do
yu=$(($yu+$i))
done
echo "剩余磁盘容量:$((($yu+$yunswap)/1000)) GB"
echo "############# 安全信息#############"
Currentuser=`whoami`
echo " 当前用户: $Currentuser"
md5sum /etc/passwd >/opt/passwd.db
md5sum -c /opt/passwd.db &>/dev/null
if [ $? -eq 0 ];then
echo " 用户异常:否"
else
echo " 用户异常:是"
fi