Lab session summarizer for Raspberry pi, running on Debian shell
shell_analytics is a shell script designed to help electronics engineers and Linux users to analyze usage logs from Raspberry Pi associated with labs that are under development & not released. This script works with both Buster and Bullseye pi devices. It parses /var/log/analytics.log to identify user sessions, calculate durations, and flag overuse patterns.
- This script runs inside the Raspberry Pi associated with Lab Hardware
- Parses logs for
SessionStart,SessionEnd, andactive_timefrom/var/log/analytics.logfile. - Handles missing
SessionEndby usingSessionStart + active_time. - Flags sessions over 45 minutes.
- Sorts session reports by Start Time.
- Filters out
device_idle, internal domains, and null users. - Shows the result in a table in shell.
- Works on Raspberry Pi with both Buster and Bullseye.
| Version | Description |
|---|---|
buster_analytics_v1.sh.bak |
Initial parsing with basic fields, added active_time |
buster_analytics_v2.sh.bak |
Added time range filtering, redundant entries |
buster_analytics_v3.sh.bak |
Sorted by Start Time, deduplicated sessions |
buster_analytics_v4.sh.bak |
Added Progress bar for easy visualization, fully cron-ready |
buster_analytics_v5.sh |
Latest version, handled SessionEnd missing |
bullseye_analytics_v1.sh |
Latest version, ported from buster_analytics_v5.sh |
bash buster_analytics_v5.sh| Flag | Description | Example |
|---|---|---|
-t |
Time range in days (default: 10) | -t 30 |
-f |
Custom log file path (default: /var/log/analytics.log) | -f /home/pi/test.log |
bash buster_analytics_v5.sh -t 14 -f /home/pi/mylog.log| Start Time | End Time | Duration | Notes | |
|---|---|---|---|---|
user1@example1.com |
2025-07-07 12:00:00 |
2025-07-07 12:45:10 |
49m |
Over 45 min |
user2@example2.com |
2025-07-11 11:06:52 |
2025-07-11 11:27:52 |
21m |
- Make sure
analytics.logis accessible. - The script skips:
- users like
device_idle - emails ending in
@tenxerlabs.comor@kimshuka.com - null or empty user names
- users like
| Condition | Calculation |
|---|---|
Has SessionStart + SessionEnd |
Use difference of timestamps |
Has SessionStart but missing SessionEnd |
Add active_time to SessionStart |
Only active_time present |
Ignored (cannot infer session window) |
Pure Shell: Works out of the box with bash, awk, and date. No need for jq, Python, or any external library.
If get error at line 4, install gawk by running sudo apt-get install -y gawk
If you're an electronics engineer who’s new to Linux:
- These scripts are plug-and-play.
- You can customize time ranges, change log paths, or auto-save reports with cron.
- Safe to run on Raspberry Pi, BeagleBone, or any ARM/Debian device running on Debian Buster or Bullseye.
- Add HTML or CSV export
- Include user activity heatmaps
- Integrate with Grafana dashboards or email alerts
- Create a folder first as
/home/pi/saved_analytics/to save the results - To schedule it every day at 6 AM and save reports with date:
crontab -eAdd this line:
0 6 * * * bash /home/pi/buster_analytics_v5.sh > /home/pi/saved_analytics/analytics_$(date +\%Y\%m\%d).txt 2>/dev/nullThis will save a new .txt file daily in /home/pi/saved_analytics/.
To test it every minute:
* * * * * bash /home/pi/buster_analytics_v5.sh > /home/pi/saved_analytics/test_run_$(date +\%Y\%m\%d_%H%M).txt 2>/dev/null