2021-08-16

#!/bin/bash

auth:Bertram

func:sys info check

version:v1.0

sys:centos6.x/7.x

[ KaTeX parse error: Expected 'EOF', got '&' at position 17: …id -u) -ne 0 ] &̲& echo "请用root用…(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 KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲')-`date +%Y%m%…(ifconfig |awk ‘NR==2{print $2}’)-date +%Y%m%d.txt”

获取系统cpu信息

function get_cpu_info() {
Physical_CPUs= ( g r e p " p h y s i c a l i d " / p r o c / c p u i n f o ∣ s o r t ∣ u n i q ∣ w c − l ) V i r t C P U s = (grep "physical id" /proc/cpuinfo| sort | uniq | wc -l) Virt_CPUs= (grep"physicalid"/proc/cpuinfosortuniqwcl)VirtCPUs=(grep “processor” /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep “cores” /proc/cpuinfo|uniq| awk -F ': ’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') CPU_Type=(grep “model name” /proc/cpuinfo | awk -F ': ’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲' | sort | uniq…(uname -m)

#echo -e ‘\033[32m CPU信息:\033[0m’
echo -e ‘\033[05;32m CPU信息:\033[0m’
cat <<EOF | column -t
物理CPU个数: $Physical_CPUs
逻辑CPU个数: $Virt_CPUs
每CPU核心数: $CPU_Kernels
CPU型号: $CPU_Type
CPU架构: $CPU_Arch
EOF
}

获取系统内存信息

function get_mem_info() {
Total=$(free -m | sed -n ‘2p’ | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 5: 2"M"}̲') Used=(free -m | sed -n ‘2p’ | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 5: 3"M"}̲') Rate=(free -m | sed -n ‘2p’ | awk ‘{print""($3/$2)*100"%"}’)

echo -e ‘\033[05;31m 内存信息:\033[0m’
cat <<EOF | column -t
内存总容量: T o t a l 内 存 已 使 用 : Total 内存已使用: Total使Used
内存使用率:$Rate

EOF
}

获取系统网络信息

function get_net_info() {
pri_ipadd=$(ifconfig |awk 'NR==2{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') #pub_ipadd=(curl ip.sb 2>&1)
pub_ipadd=$(curl -s http://ddns.oray.com/checkip | awk -F “:” ‘{print $2}’ | awk -F “<” ‘{print $1}’|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲') gateway=(ip route | grep default | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 3}̲') mac_info=(ip link| egrep -v “lo”|grep link|awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') dns_config=(egrep ‘nameserver’ /etc/resolv.conf)
route_info=$(route -n)

echo -e ‘\033[05;33m IP信息:\033[0m’
cat <<EOF | column -t
系统公网地址: ${pub_ipadd}
系统私网地址: ${pri_ipadd}
网关地址: ${gateway}
MAC地址: ${mac_info}

路由信息:
${route_info}

DNS 信息:
${dns_config}
EOF
}

获取系统磁盘信息

function get_disk_info() {
disk_info= ( f d i s k − l ∣ g r e p " D i s k / d e v " ∣ c u t − d , − f 1 ) d i s k u s e = (fdisk -l|grep "Disk /dev"|cut -d, -f1) disk_use= (fdisklgrep"Disk/dev"cutd,f1)diskuse=(df -hTP|awk ' 2 ! = " t m p f s " p r i n t ′ ) d i s k i n o d e = 2!="tmpfs"{print}') disk_inode= 2!="tmpfs"print)diskinode=(df -hiP|awk ‘$1!=“tmpfs”{print}’)

echo -e ‘\033[05;34m 磁盘信息:\033[0m’
cat <<EOF
${disk_info}
磁盘使用:
${disk_use}
inode信息:
${disk_inode}
EOF
}

获取系统信息

function get_systatus_info() {
sys_os= ( u n a m e − o ) s y s r e l e a s e = (uname -o) sys_release= (unameo)sysrelease=(cat /etc/redhat-release)
sys_kernel= ( u n a m e − r ) s y s h o s t n a m e = (uname -r) sys_hostname= (unamer)syshostname=(hostname)
sys_selinux= ( g e t e n f o r c e ) s y s l a n g = (getenforce) sys_lang= (getenforce)syslang=(echo L A N G ) s y s l a s t r e b o o t = LANG) sys_lastreboot= LANG)syslastreboot=(who -b | awk '{print $3,KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲') sys_runtime=(uptime |awk '{print $3,KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲'|cut -d, -f1) …(date)
sys_load=$(uptime |cut -d: -f5)

echo -e ‘\033[05;35m 系统信息:\033[0m’
cat <<EOF | column -t
系统: ${sys_os}
发行版本: ${sys_release}
系统内核: ${sys_kernel}
主机名: ${sys_hostname}
selinux状态: ${sys_selinux}
系统语言: ${sys_lang}
系统当前时间: ${sys_time}
系统最后重启时间: ${sys_lastreboot}
系统运行时间: ${sys_runtime}
系统负载: ${sys_load}
EOF
}

获取服务信息

function get_service_info() {
port_listen= ( n e t s t a t − l n t u p ∣ g r e p − v " A c t i v e I n t e r n e t " ) k e r n e l c o n f i g = (netstat -lntup|grep -v "Active Internet") kernel_config= (netstatlntupgrepv"ActiveInternet")kernelconfig=(sysctl -p 2>/dev/null)
if [ s y s v e r s i o n − g t 6 ] ; t h e n s e r v i c e c o n f i g = {sysversion} -gt 6 ];then service_config= sysversiongt6];thenserviceconfig=(systemctl list-unit-files --type=service --state=enabled|grep “enabled”)
run_service= ( s y s t e m c t l l i s t − u n i t s − − t y p e = s e r v i c e − − s t a t e = r u n n i n g ∣ g r e p " . s e r v i c e " ) e l s e s e r v i c e c o n f i g = (systemctl list-units --type=service --state=running |grep ".service") else service_config= (systemctllistunitstype=servicestate=runninggrep".service")elseserviceconfig=(/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 <<EOF
${service_config}
${line}
运行的服务:

${run_service}
${line}
监听端口:

${port_listen}
${line}
内核参考配置:

${kernel_config}
EOF
}

function get_sys_user() {
login_user=KaTeX parse error: Expected '}', got 'EOF' at end of input: (awk -F: '{if (NF=="/bin/bash") print KaTeX parse error: Expected 'EOF', got '}' at position 2: 0}̲' /etc/passwd) …(egrep -v "#| " / e t c / s s h / s s h d c o n f i g ) s u d o c o n f i g = " /etc/ssh/sshd_config) sudo_config= "/etc/ssh/sshdconfig)sudoconfig=(egrep -v "#| " / e t c / s u d o e r s ∣ g r e p − v " D e f a u l t s " ) h o s t c o n f i g = " /etc/sudoers |grep -v "^Defaults") host_config= "/etc/sudoersgrepv"Defaults")hostconfig=(egrep -v “#| " / e t c / h o s t s ) c r o n d c o n f i g = " /etc/hosts) crond_config= "/etc/hosts)crondconfig=(for cronuser in /var/spool/cron/* ;do ls KaTeX parse error: Expected group after '^' at position 46: … -f5;egrep -v "^̲|^#” ${cronuser} 2>/dev/null;echo “”;done)

echo -e ‘\033[05;37m 系统登录用户:\033[0m’
cat <<EOF
${login_user}
${line}
ssh 配置信息:

${ssh_config}
${line}
sudo 配置用户:

${sudo_config}
${line}
定时任务配置:

${crond_config}
${line}
hosts 信息:

${host_config}
EOF
}

function process_top_info() {

top_title= ( t o p − b n 1 ∣ h e a d − 7 ∣ t a i l − 1 ) c p u t o p 10 = (top -b n1|head -7|tail -1) cpu_top10= (topbn1head7tail1)cputop10=(top b -n1 | head -17 | tail -10)
mem_top10=$(top -b n1|head -17|tail -10|sort -k10 -r)

echo -e ‘\033[05;38m CPU占用top10:\033[0m’
cat <<EOF
${top_title}
${cpu_top10}

EOF

echo -e ‘\033[05;39m 内存占用top10:\033[0m’
cat <<EOF
${top_title}
${mem_top10}
EOF
}

function sys_check() {
get_cpu_info
echo ${line}
get_mem_info
echo ${line}
get_net_info
echo ${line}
get_disk_info
echo ${line}
get_systatus_info
echo ${line}
get_service_info
echo ${line}
get_sys_user
echo ${line}
process_top_info
}
sys_check > ${sys_check_file}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值