This script provides an interactive, menu-driven way to perform CPU, memory, and combined stress tests on any Linux server. It uses the popular stress tool to simulate high load and helps you monitor system resource usage in real time.
- Install stress tools: Installs
stress,stress-ng, andhtopfor load testing and monitoring. - Show system information: Displays CPU cores, total/available memory, and load average.
- CPU stress test: Runs a CPU load test for a configurable duration and number of workers.
- Memory stress test: Allocates and stresses a configurable amount of memory for a set duration.
- Combined CPU & Memory stress test: Simultaneously stresses CPU and memory.
- Custom stress test: Lets you configure duration, CPU workers, and memory allocation.
- Resource monitoring: Shows CPU and memory usage during tests.
- A Linux server (tested on Ubuntu, Debian, Amazon Linux, CentOS, RHEL).
- Root or sudo privileges to install packages.
Copy the script file linux-stress-test.sh to your Linux server.
chmod +x linux-stress-test.sh./linux-stress-test.shYou will see a menu like:
=== Stress Test Options ===
1. Install stress tools
2. Show system information
3. CPU stress test
4. Memory stress test
5. Combined CPU & Memory stress test
6. Custom stress test
7. Exit
- Option 1: Installs required tools (
stress,stress-ng,htop). - Option 2: Displays system info.
- Option 3: Prompts for duration and CPU workers, then runs a CPU stress test.
- Option 4: Prompts for duration and memory size, then runs a memory stress test.
- Option 5: Prompts for duration, then runs a combined test with default CPU/memory.
- Option 6: Lets you set duration, CPU workers, and memory allocation.
- Option 7: Exits the script.
During tests, the script will display CPU and/or memory usage every 5 seconds. Press Ctrl+C to stop monitoring if needed.
To run a CPU stress test for 120 seconds with 4 workers:
- Select option 3.
- Enter
120for duration. - Enter
4for number of workers.
- The script automatically detects your package manager (
yumorapt) and installs tools as needed. - For best results, run as root or with sudo privileges.
- Use with caution on production systems.
Author:
Ankush
