Posts

Showing posts from January, 2025

Shell script for system and process monitor

Below is a simple shell script that can SSH from one host to four other remote hosts and checks the memory, CPU usage, and currently running processes for an application. If the CPU or memory usage exceeds 85%, the script will log it and send the output via email in a table format. Assumptions: 1. The script assumes SSH access to the remote hosts is already set up (using SSH keys or passwordless SSH). 2. The script uses `ps`, `top`, `free`, and `awk` for system resource information. 3. The `mail` command is available on the system for sending emails. Script: `check_resources.sh` ```bash #!/bin/bash Define the list of remote hosts HOSTS=("host1" "host2" "host3" "host4") Define the application name to monitor (replace with your app name) APP_NAME="your_application_name" Define the email recipient EMAIL_RECIPIENT="your_email@example.com" Define the log file LOG_FILE="/tmp/resource_usage_log.txt" Initialize the ...