SHELL 日常巡检
SHELL 日常巡检
#!/bin/bash
function system(){
echo "#####################################系统信息###########################"
OS_TYPE=`uname`
OS_VER=`cat/etc/redhat-release`
OS_KEY=`uname -a|awk '{print $3}'`
OS_TIME=`date +%F_%T`
OS_RUN_TIME=` uptime |awk '{print $3,$4}'|awk -F, '{print $1}'`
OS_LAST_REBOOT_TIME=` who -b|awk '{print $3}'`
OS_HOSTNAME= `hostname`
echo " 系统类型: $OS_TYPE"
echo " 系统版本: $OS_VER"
echo " 系统内核: $OS_KER"
echo " 当前时间: $OS_TIME"
echo " 运行时间: $OS_RUN_TIME"
echo " 最后启动时间: $OS_LAST_REBOOT_TIME"
echo " 本机名称: $OS_HOSTNAME"
}
function network(){
echo "##########################################网络信息################################"
INTERNET=(`ifconfig |grep -w inet|awk '{print $2}'`)
echo " 本机IP: ${INTERNET}"
curl -I http://www.baidu.com &>/dev/null
if [ $? -eq 0 ]
then echo " 访问外网: 成功"
else echo " 访问外网: 失败"
fi
}
function network(){
echo "#########################################硬件信息#################################"
CPUID=`grep "physical id" /proc/cpuinfo |sort|uniq|wc -l`
CPUCORES=` grep "cores" /proc/cpuinfo |sort|uniq|awk -F: '{print $2}'`
CPUMODE=` grep "model name" /proc/cpuinfo |sort|uniq |awl -F: '{print $2}'`
echo " CPU数量:$CPUID"
echo " CPU核心:$CPUCORES"
echo " CPU型号:$CPUMODE"
MEMTOTAL=` free -m |grep Mem |awk '{print $2}'`
MEMFREE= `free -m |grep Mem | awk '{print $4}'`
echo " 内存总容量: ${MEMTOTAL}MB"
echo "剩余内存容量: ${MEMFREE}MB"
disksize=0
swapsize=`free|grep Swap|awk {'print $2'}`
partitionsize=(` df -T|sed 1d|egrep -v "tmpfs"|awk {'print $3'}`)
for ((i=0;i< `echo ${#partitionsize[*]}`;i++))
do
disksize=`expr $disksize + ${partitionsize[$i]}`
done
#1KB=1024B。
#1MB=1024KB。
#1GB=1024MB。
((disktotal=\($disksize+$swapsize\)/1024/1024))
echo " 磁盘总容量: ${disktotal}GB"
diskfree=0
swapfree=`free|grep Swap|awk '{print $4}'`
partitionfree=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk '{print $5}'`)
for ((i=0;i<`echo ${#partitionfree[*]}`;i++))
do
diskfree=`expr $diskfree + ${partitionfree[$i]}`
done
((freetotal=\($diskfree+$swapfree\)/1024/1024))
echo "剩余磁盘容量:${freetotal}GB"
}
function secure(){
echo "#########################安全信息#########################"
countuser=(`last|grep "still logged in"|awk '{print $1}'|sort|uniq`)
for ((i=0;i<`echo ${#countuser[*]}`;i++))
do echo "当前登录用户:${countuser[$i]}"
done
md5sum /etc/passwd > /opt/passwd.db
md5sum -c --quiet /opt/passwd.db &>/dev/null
if [ $? -eq 0 ]
then echo " 用户异常:否"
else echo " 用户异常:是"
fi
}
function chksys(){
system
network
hardware
secure
}
chksys
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步