A shell script to monitor system memory usage with email alerts, audio notifications, and TSV logging.
- Real-time memory usage monitoring
- Email alerts when memory usage exceeds threshold
- Includes top 5 memory-consuming processes and their usage percentages
- Automated process monitoring and reporting
- Audio notifications using espeak
- Detailed logging in TSV format
- Automated monitoring through cron jobs
# For Debian/Ubuntu
sudo apt-get install sendmail espeak bc
# For Red Hat/CentOS
sudo yum install sendmail espeak bc- Clone the repository:
git clone https://github.com/yourusername/memory-monitor.git
cd memory-monitor- Make the script executable:
chmod +x memory_monitor.sh- Configure the script:
- Open
memory_monitor.shand set:EMAIL="your_email@example.com" # Your email address THRESHOLD=90 # Memory threshold percentage LOG_FILE="mem_report.tsv" # Log file location
./memory_monitor.shSet up hourly monitoring using crontab:
# Open crontab editor
crontab -e
# Add this line
0 * * * * /path/to/memory_monitor.sh
# Verify cron job
crontab -lMemory usage: 72.45%
Memory usage logged to mem_report.tsv
Alert email sent! Memory usage: 92.33%
Memory usage logged to mem_report.tsv
[Voice Alert]: "Warning! Memory usage is at 92.33 percent"
Subject: Memory Alert: High Usage Detected
Warning: Memory usage is at 92.33%
Top Memory-Consuming Processes (Process:Memory%):
chrome:15.2%|firefox:8.5%|mysql:6.7%|nodejs:4.2%|python:3.8%|
Timestamp Memory_Usage(%) Alert_Status
2024-12-23 14:00:00 72.45 OK
2024-12-23 15:00:00 92.33 ALERT
2024-12-23 16:00:00 85.67 OK
- Check sendmail status:
systemctl status sendmail- Test email:
echo "Test" | mail -s "Test" your_email@example.com- Check espeak:
espeak "Test message"- Check cron service:
systemctl status cron- View cron logs:
grep CRON /var/log/syslog