Linux系统巡检脚本
#!/bin/bash
# auth:Bertram
# created Time : 2019-12-26
# func:sys info check
# sys:centos6.x/7.x
-------------------------------------------------------------------------------------------------------------------------------------
[ $(id -u) -ne 0 ] && echo "请用root用户执行此脚本!" && exit 1
sysversion=$(rpm -q centos-release|cut -d- -f3)
line="-------------------------------------------------"
[ -d logs ] || mkdir logs
#sys_check_file="logs/$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt"
sys_check_file="logs/$(ifconfig |awk 'NR==2{print $2}')-`date +%Y%m%d`.txt"
# 获取系统cpu信息
function get_cpu_info() {
Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
CPU_Arch=$(uname -m)
#echo -e '\033[32m CPU信息:\033[0m'
echo -e '\033[05;32m CPU信息:\033[0m'
cat <&1)
pub_ipadd=$(curl -s http://dDNS.oray.com/checkip | awk -F ":" '{print $2}' | awk -F "<" '{print $1}'|awk '{print $1}')
gateway=$(ip route | grep default | awk '{print $3}')
mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}')
dns_config=$(egrep 'nameserver' /etc/resolv.conf)
route_info=$(route -n)
echo -e '\033[05;33m IP信息:\033[0m'
cat </dev/null)
if [ ${sysversion} -gt 6 ];then
service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled")
run_service=$(systemctl list-units --type=service --state=running |grep ".service")
else
service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t)
run_service=$(/sbin/service --status-all|grep -E "running")
fi
echo -e '\033[05;36m 服务启动配置:\033[0m'
cat </dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done)
echo -e '\033[05;37m 系统登录用户:\033[0m'
cat < ${sys_check_file}
结果如图 :
成都地区优秀IDC服务器托管提供商(创新互联建站).为客户提供专业的川西大数据中心,四川各地服务器托管,川西大数据中心、多线服务器托管.托管咨询专线:18980820575
网站标题:Linux系统巡检脚本
当前地址:http://azwzsj.com/article/josgje.html