This project contains a Bash script that performs automated system audits and logs detailed hardware and performance metrics to log files in /var/log.
- CPU Information: Captures processor family, model, core count, and thread information
- Memory Usage: Logs current memory utilization in human-readable format
- Network Configuration: Extracts and masks IP addresses for security
- System Uptime: Logs system uptime and per-user process count
- Process Monitoring: Counts active processes for the current user
- Automatic Logging:Ensures log folder and file exist
All runtime logs are written to: /var/log/system_logs/system_logs.log
The script will create /var/log/system_logs and the log file if missing (requires sudo for initial creation and or to change ownership).
Make script executable:
chmod +x system_monitor.shRun manually:
bash system_monitor.sh- Threshold is set in the script (
Thresholdvariable, default 80). - When memory usage >= threshold the script logs a warning and attempts a Windows popup:
/mnt/c/Windows/System32/cmd.exe /c msg * "[Critical] Memory Usage: ${Percentage_used}%" - Requirements/notes:
- Works under WSL with Windows
msgavailable; - On full Linux desktop use
notify-sendor another local notifier instead(Make sure dependencies are installed) - Adjust
Thresholdinsidesystem_monitor.shto change behavior.
- Works under WSL with Windows
Place a logrotate config in /etc/logrotate.d/ to rotate and compress logs. Example config:
// filepath: /etc/logrotate.d/system_usage
/var/log/system_logs/system_logs.log {
weekly #create new log files every week
rotate 4 #after 4 weeks, rotate and compress
create 0640 your_username your_username
compress # compress to .gz
delaycompress #wait till a rotation is done before zipping
missingok
notifempty #if file is empty, do not do anything; no rotatin
}
the logrotate configuration is in the repo as (system_usage), you can configure it with
sudo cp system_usage /etc/logrotate.d/system_usage
sudo chown root:user /etc/logrotate.d/system_usage
sudo chmod 0644 /etc/logrotate.d/system_usageCreate directory and set secure ownership/permissions:
sudo mkdir -p /var/log/system_logs
sudo touch /var/log/system_logs/system_logs.log
sudo chown root:$user /var/log/system_logs /var/log/system_logs/system_logs.log
sudo chmod 0755 /var/log/system_logs
sudo chmod 0640 /var/log/system_logs/system_logs.logTest and force rotation:
sudo logrotate -f /etc/logrotate.d/system_monitor # force rotation to see if it'd work under normal circumstances
## Scheduling
Run periodically with cron or a systemd timer. Example cron (every 5 hours from 9am):
```cron
0 9,14,19,0,5 * * * /path_to_your_folder- Edit
system_monitor.shto change interface name (IP extraction), user for process counting, orThreshold. - If logs are not written, check file permissions and run the script manually to inspect errors.
- On WSL, Windows popup behavior depends on Windows configuration and session permissions.
- Minimal toolset; intended for simple local monitoring and education.
- Keep log access restricted due to sensitive system data.