vlambda博客
学习文章列表

shell-linux系统基础巡检脚本

#!/bin/bash#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 usedmem_used=`free -m |grep Mem |awk '{print $3/$2*100"%"}'`swap_used=`free -m |grep Swap |awk '{print $3/$2*100"%"}'`
#disk useddisk_used=`df -TPh|awk '{print $6,$7}' |grep -v Use`
#cpu loadload1=`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 usedcpu_us=`vmstat | awk '{print $13}'|grep -v us`cpu_sy=`vmstat | awk '{print $14}'|grep -v sy`
#running timerun_time=` uptime | awk -F, '{print $1}' |awk '{print $2,$3,$4}'`

echoecho "*************************************************"echo "$name"echo "*************************************************"printf "system version:\t%s\n" $system_verprintf "kernel version:\t%s\n" $kernel_verprintf "hostname:\t%s\n" $hostnameecho "ipaddress:$ip"echo "********************MEMORY************************"printf "memory used:\t%s\n" $mem_usedprintf "swap used:\t%s\n" $swap_usedecho "********************DISK USED*************************"echo "$disk_used"echo "********************CPU***************************"printf "CPU_load1:\t%s\n" $load1printf "CPU_load5:\t%s\n" $load5printf "CPU_load15:\t%s\n" $load15printf "CPU_loadavg:\t%s\n" $loadavgprintf "CPU_us:\t%s\n" $cpu_usprintf "CPU_sy:\t%s\n" $cpu_sy echo "***************RUN TIME***************************"echo "running time: $run_time"echo "***************************************************"