A lightweight, automated Linux server monitoring and maintenance suite written in Bash. Designed to run on any modern systemd-based Linux distribution with no external runtime dependencies beyond standard system utilities.
- Real-time terminal dashboard displaying CPU, memory, disk, and load average metrics
- Configurable threshold-based alerting with optional email notification
- Automatic detection and restart of failed critical services with retry logic
- Daily system health report generation with optional email delivery
- Log rotation with age-based deletion, size-based compression, and archive pruning
- Weekly system package upgrades and temporary file cleanup
- Security-only OS patching with support for multiple package managers
- Single-command cron job installation for full automation
linux-monitoring-system/
├── config.cfg # Central configuration file
├── monitor.sh # Interactive real-time dashboard
├── alerts.sh # Metric threshold checker and alerter
├── self_heal.sh # Critical service monitor and auto-restarter
├── report.sh # Daily system report generator
├── log_rotation.sh # Log cleanup, compression, and pruning
├── maintenance.sh # Weekly package updates and system cleanup
├── security_update.sh # Security-only OS patching
├── setup_cron.sh # Cron job installer (run once)
├── logs/ # Runtime log files (auto-created)
└── reports/ # Generated report files (auto-created)
- Bash 4.0 or later
bc— floating-point arithmetic for threshold comparisonssystemctl— service management (systemd-based systems only)mail— optional, required for email alertinggziporzip— optional, for log and report compressionmpstat— optional, for extended CPU statistics in reports (provided by thesysstatpackage)
1. Clone the repository
git clone https://github.com/YOUR_USERNAME/linux-monitoring-system.git
cd linux-monitoring-system2. Edit the configuration file
nano config.cfgAt minimum, update the following:
EMAIL_RECIPIENT— destination address for alert and report emailsCRITICAL_SERVICES— space-separated list of services to monitor and auto-heal- Threshold values as appropriate for your environment
3. Make all scripts executable
chmod +x *.sh4. Install cron jobs
bash setup_cron.shThis is a one-time operation. The script is idempotent and safe to re-run.
5. Launch the live dashboard
bash monitor.shAll settings are defined in config.cfg and sourced by every script at runtime.
| Variable | Default | Description |
|---|---|---|
CPU_WARN / CPU_CRIT |
70 / 80 | CPU usage alert thresholds (%) |
MEMORY_WARN / MEMORY_CRIT |
65 / 75 | Memory usage alert thresholds (%) |
DISK_WARN / DISK_CRIT |
75 / 85 | Disk usage alert thresholds (%) |
LOAD_WARN / LOAD_CRIT |
3 / 5 | Load average alert thresholds |
REFRESH_INTERVAL |
5 | Dashboard refresh interval (seconds) |
EMAIL_ENABLED |
true | Enable or disable email notifications |
EMAIL_RECIPIENT |
(configure this) | Email address for alerts and reports |
CRITICAL_SERVICES |
sshd nginx mysql |
Services subject to auto-healing |
MAX_RESTART_RETRIES |
3 | Maximum restart attempts per service |
LOG_RETENTION_DAYS |
30 | Number of days before logs are deleted |
LOG_MAX_SIZE_MB |
50 | Log file size threshold for compression (MB) |
MAX_ROTATED_FILES |
10 | Maximum number of compressed archives to retain per log family |
Log files written at runtime (inside logs/):
| Variable | File | Written by |
|---|---|---|
ALERT_LOG |
logs/alerts.log |
alerts.sh |
SELF_HEAL_LOG |
logs/self_heal.log |
self_heal.sh |
SECURITY_LOG |
logs/security_update.log |
security_update.sh |
MAINTENANCE_LOG |
logs/maintenance.log |
maintenance.sh |
Installed automatically by setup_cron.sh.
| Script | Schedule |
|---|---|
alerts.sh, self_heal.sh |
Every 5 minutes |
report.sh |
Daily at 23:59 |
log_rotation.sh |
Daily at 00:00 |
maintenance.sh |
Every Sunday at 02:00 |
security_update.sh |
Every Sunday at 03:00 |
To remove all installed cron jobs:
crontab -l | sed "/# LINUX-MONITORING-SYSTEM-START/,/# LINUX-MONITORING-SYSTEM-END/d" | crontab -| Distribution | Package Manager | Security Update Method |
|---|---|---|
| Ubuntu / Debian | apt-get |
unattended-upgrade |
| RHEL / CentOS / Rocky / AlmaLinux | dnf / yum |
--security flag |
| Fedora | dnf |
--security flag |
| Arch Linux | pacman |
Full system upgrade |
MIT License. Free to use, modify, and distribute.