Created
January 12, 2026 15:52
-
-
Save krameraad/c77260455205b7cf590f5f5718088055 to your computer and use it in GitHub Desktop.
Monitoring script for the 42 Born2BeRoot project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| architecture=$(uname -a) | |
| n_cpu=$(grep "physical id" /proc/cpuinfo | wc -l) | |
| n_vcpu=$(grep processor /proc/cpuinfo | wc -l) | |
| mem_use=$(free --mega | awk '$1 == "Mem:" {printf("%d/%d (%.2f%%)"), $3, $2, $3/$2*100}') | |
| disk_use=$(df -m | grep "/dev/" | grep -v "/boot" | \ | |
| awk '{use += $3} {total += $2} END {printf("%d/%dMB (%d%%)\n"), use, total, use/total*100}') | |
| cpu_load=$(vmstat 1 4 | tail -1 | awk '{printf("%d%%"), 100-$15}') | |
| last_boot=$(who -b | awk '{print $3, $4, $5}') | |
| lvm_use=$(lsblk | grep -q lvm && echo "yes" || echo "no") | |
| connect_tcp=$(ss -t | grep ESTAB | wc -l) | |
| users=$(who | wc -l) | |
| network=$(hostname -I | awk '{print $1}')\ $(ip link show | grep link/ether | awk '{print $2}') | |
| sudo_use=$(grep -c "COMMAND=" /var/log/sudo/sudo.log) | |
| echo " System monitoring | |
| --------------------- | |
| Architecture: $architecture | |
| CPU's: $n_cpu | |
| vCPU's: $n_vcpu | |
| Memory usage: $mem_use | |
| Disk usage: $disk_use | |
| CPU load: $cpu_load | |
| Last boot: $last_boot | |
| LVM use: $lvm_use | |
| Connections (TCP): $connect_tcp | |
| Users logged in: $users | |
| Network (IPv4, MAC): $network | |
| Sudo: $sudo_use" | |
| # With escape sequences: | |
| # echo " | |
| # \033[1m System monitoring \033[0m | |
| # \033[2m---------------------\033[0m | |
| # \033[0mArchitecture: \033[1m$architecture | |
| # \033[0mCPU's: \033[1m$n_cpu | |
| # \033[0mvCPU's: \033[1m$n_vcpu | |
| # \033[0mMemory usage: \033[1m$mem_use | |
| # \033[0mDisk usage: \033[1m$disk_use | |
| # \033[0mCPU load: \033[1m$cpu_load | |
| # \033[0mLast boot: \033[1m$last_boot | |
| # \033[0mLVM use: \033[1m$lvm_use | |
| # \033[0mConnections (TCP): \033[1m$connect_tcp | |
| # \033[0mUsers logged in: \033[1m$users | |
| # \033[0mNetwork: \033[1m$network | |
| # \033[0mSudo: \033[1m$sudo_use | |
| # \033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment