Skip to content

Instantly share code, notes, and snippets.

@wouterds
Created August 26, 2024 14:50
Show Gist options
  • Save wouterds/e1d87f48b41de8bc558a309d4eb982b3 to your computer and use it in GitHub Desktop.
Save wouterds/e1d87f48b41de8bc558a309d4eb982b3 to your computer and use it in GitHub Desktop.

Revisions

  1. wouterds created this gist Aug 26, 2024.
    15 changes: 15 additions & 0 deletions system.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash

    # Get used RAM percentage
    ram_used=$(free | awk '/Mem:/ {printf "%.2f", $3/$2 * 100}')

    # Get average CPU usage percentage
    cpu_used=$(top -bn2 -d 0.5 | grep "Cpu(s)" | tail -n 1 | awk '{print $2 + $4}')

    # Get used disk space percentage across all disks
    disk_used=$(df -h --total | awk '/total/ {print $5}' | sed 's/%//')

    # Print results
    echo "Used RAM: ${ram_used}%"
    echo "CPU Usage: ${cpu_used}%"
    echo "Used Disk Space: ${disk_used}%"