1. monitoring 만들기

더보기
#!/bin/bash

uname_all=$(uname --all)
cpu_pro=$(grep "physical id" /proc/cpuinfo | uniq | wc -l)
vcpu_pro=$(grep "^processor" /proc/cpuinfo | wc -l)
memory_use=$(free --mega | grep Mem | awk '{printf("%i/%iMB (%.2f%%)\n", $3, $2, $3/$2*100)}')
disk_usd=$(df --total --human-readable | grep "total" | awk '{printf("%s/%s (%s)\n", $3, $4, $5)}')
cpu_load=$(top -bn1 | grep "%Cpu" | awk '{printf("%.1f%%\n", (100.0-$8)%100)}')
last_boot=$(who --boot | awk '{printf("%s %s", $3, $4)}')
lvm_use=$(if [ $(lsblk | grep "lvm" | wc -l) -eq 0 ]; then echo "no"; else echo "yes"; fi)
tcp_con=$(ss -s | grep "TCP:" | tr ',' ' ' | awk '{printf("%s ESTABLISHED\n", $4)}')
user_log=$(who --count | grep "users" | tr '=' ' ' | awk '{print $3}')
ip=$(hostname -I)
mac_ip=$(ip a | grep $ip -B 3 | awk '$1 == "link/ether" {print $2}' | head -n 1)
sudo_work=$(sudo find /var/log/sudo/*/*/* -type d | wc -l)
#sudo_work=$(journalctl _COMM=sudo | grep COMMAND | wc -l)

wall "	#Architecure: $uname_all
	#CPU physical : $cpu_pro
	#vCPU : $vcpu_pro
	#Memory Usage: $memory_use
	#Disk Usage: $disk_usd
	#CPU load: $cpu_load
	#Last boot: $last_boot
	#LVM use: $lvm_use
	#Connection TCP : $tcp_con
	#User log: $user_log
	#Network: IP $ip($mac_ip)
	#Sudo : $sudo_work cmd"

 2. 자동 출력 

 - crontab -e 

 - 추가

 -- */10 * * * * /bin/monitoring.sh

끝!

 

블로그 이미지

Or71nH

,