YBee24 / Yasmina-and-Lucien-Shell-Problem-Project-Friday-26-July

0 stars 0 forks source link

generate downloadable report #12

Open Luciensday opened 1 month ago

YBee24 commented 1 month ago

!/bin/bash

Function to check CPU usage

check_cpu_usage() { echo "CPU Usage:"

Display average CPU load over the last 1, 5, and 15 minutes

uptime | awk '{printf "1 min: %-6s 5 min: %-6s 15 min: %-6s\n", $(NF-2), $(NF-1), $NF}'
echo ""

}

Function to find the top 5 CPU-consuming processes

top_cpu_processes() { echo "Top 5 CPU-consuming processes:" ps aux --sort=-%cpu | awk 'NR==1 || NR<=6 {printf "%-10s %-8s %-8s %-8s %s\n", $1, $2, $3, $4, $11}' echo "" }

Function to check memory usage

check_memory_usage() { echo "Memory Usage:"

Display memory usage using free command

free -h | awk 'NR==1 || NR==2 {printf "%-10s %-10s %-10s %-10s\n", $1, $2, $3, $4}'
echo ""

}

Function to find the top 5 memory-consuming processes

top_memory_processes() { echo "Top 5 memory-consuming processes:" ps aux --sort=-%mem | awk 'NR==1 || NR<=6 {printf "%-10s %-8s %-8s %-8s %s\n", $1, $2, $3, $4, $11}' echo "" }

Function to check disk usage

check_disk_usage() { echo "Disk Usage Information:" df -h | awk 'NR==1 || /^\/dev\// {printf "%-20s %-10s