#!/bin/bash
# Maximum RAM usage limit, percentage
RAM_THRESHOLD=80
# Maximum CPU usage limit, percentage
CPU_THRESHOLD=90
# Maximum CPU temperature limit, in Celsius
TEMP_THRESHOLD=50
# Check time interval, sec
INTERVAL=10
while :
do
# Get memory information
mem_info=$(free | awk '/^Mem:/{printf "%.0f", $3/$2 * 100}')
# Get CPU usage percentage
cpu_usage=$(top -b -n 1 | awk '/^%Cpu/{printf "%.0f", $2}')
# Get CPU temperature (Example command for 'sensors'; adjust based on your system)
cpu_temp_raw=$(sensors | awk '/^Core 0:/{print $3}' | cut -c 2-)
cpu_temp=${cpu_temp_raw%.*} # Remove the decimal part
# Create a message with memory, CPU, and temperature information
message="RAM Usage: $mem_info% | CPU Usage: $cpu_usage% | CPU Temperature: $cpu_temp°C"
# Check if RAM usage is above the threshold
if [ "$mem_info" -gt "$RAM_THRESHOLD" ]; then
# Send a notification if RAM usage is high
notify-send "High RAM Usage!" "$message"
fi
# Check if CPU usage is above the threshold
if [ "$cpu_usage" -gt "$CPU_THRESHOLD" ]; then
# Send a notification if CPU usage is high
notify-send "High CPU Usage!" "$message"
fi
# Check if CPU temperature is above the threshold
if [ "$cpu_temp" -gt "$TEMP_THRESHOLD" ]; then
# Send a notification if CPU temperature is high
notify-send "High CPU Temperature!" "$message"
fi
# Print the memory, CPU, and temperature information to the console
echo "$message"
# Sleep for the specified interval before checking again
sleep "$INTERVAL"
done