shell-linux系统基础巡检脚本
Posted linux言叙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell-linux系统基础巡检脚本相关的知识,希望对你有一定的参考价值。
#Linux 言叙
#2020.01.19
#version 1.0
date=`date +%F-%T`
name="$date system information check"
#系统版本、内核版本、主机名
system_ver=`cat /etc/redhat-release|sed 's/[ ]/_/g'`
kernel_ver=`uname -r`
hostname=`echo $HOSTNAME`
#ip=`ifconfig |grep Bcast|awk -F: '{printf $2}' |awk '{printf $1}'`
ip=`ip add | grep -v inet6 |grep inet |awk '{print $2,$NF}'|grep -v lo`
#memory used
mem_used=`free -m |grep Mem |awk '{print $3/$2*100"%"}'`
swap_used=`free -m |grep Swap |awk '{print $3/$2*100"%"}'`
#disk used
disk_used=`df -TPh|awk '{print $6,$7}' |grep -v Use`
#cpu load
load1=`cat /proc/loadavg | awk '{print $1}'`
load5=`cat /proc/loadavg | awk '{print $2}'`
load15=`cat /proc/loadavg | awk '{print $3}'`
loadavg=`cat /proc/loadavg|awk '{print ($1+$2+$3)/3*100}'`
#cpu used
cpu_us=`vmstat | awk '{print $13}'|grep -v us`
cpu_sy=`vmstat | awk '{print $14}'|grep -v sy`
#running time
run_time=` uptime | awk -F, '{print $1}' |awk '{print $2,$3,$4}'`
echo
echo "*************************************************"
echo "$name"
echo "*************************************************"
printf "system version:\t%s\n" $system_ver
printf "kernel version:\t%s\n" $kernel_ver
printf "hostname:\t%s\n" $hostname
echo "ipaddress:$ip"
echo "********************MEMORY************************"
printf "memory used:\t%s\n" $mem_used
printf "swap used:\t%s\n" $swap_used
echo "********************DISK USED*************************"
echo "$disk_used"
echo "********************CPU***************************"
printf "CPU_load1:\t%s\n" $load1
printf "CPU_load5:\t%s\n" $load5
printf "CPU_load15:\t%s\n" $load15
printf "CPU_loadavg:\t%s\n" $loadavg
printf "CPU_us:\t%s\n" $cpu_us
printf "CPU_sy:\t%s\n" $cpu_sy
echo "***************RUN TIME***************************"
echo "running time: $run_time"
echo "***************************************************"
以上是关于shell-linux系统基础巡检脚本的主要内容,如果未能解决你的问题,请参考以下文章