Skip to content

Instantly share code, notes, and snippets.

@vkoori
vkoori / docker.sh
Last active April 7, 2024 07:07
Get docker containers with minimal info
#!/bin/bash
flag=$1
if [ -z "$flag" ]
then
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}" | (read -r; printf "%s\n" "$REPLY"; sort -k 3)
exit
fi
@vkoori
vkoori / monitor.sh
Last active May 19, 2023 07:53
Use this shell script to find out about your server's resource usage.
#!/bin/bash
# Get CPU information
CPU_MODEL=$(grep "model name" /proc/cpuinfo | awk -F: '{print $2}' | sed 's/^[\t]*//' | head -1)
CPU_CORES=$(grep "cpu cores" /proc/cpuinfo | awk -F: '{print $2}' | sed 's/^[\t]*//' | head -1)
CPU_THREADS=$(grep "siblings" /proc/cpuinfo | awk -F: '{print $2}' | sed 's/^[\t]*//' | head -1)
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
# Get memory information
MEM_TOTAL=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')