Created
April 28, 2024 09:10
-
-
Save mydansun/39fcff342b2f683e4c1fe9fd4ef925f1 to your computer and use it in GitHub Desktop.
Run CPU test
This file contains 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 | |
# Get CPU usage | |
# Use the top command in batch mode to run once, take the first line, use awk to get the 8th column (idle value), | |
# then subtract it from 100 to get the CPU usage percentage. | |
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}') | |
CPU_USAGE=${CPU_USAGE%.*} | |
# Check if the CPU usage is less than 20% | |
if [ "$CPU_USAGE" -lt 20 ]; then | |
# Calculate the number of processors | |
PROC_COUNT=$(cat /proc/cpuinfo | grep "processor" | wc -l) | |
# Run the sysbench command | |
sysbench --time=120 --threads=$PROC_COUNT cpu run | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment