journal-cron.sh

ODROID-M1 (Hardkernel) · File : journal-cron.sh · Language : Bash · Use case : Journaliser une mesure toutes les minutes avec cron

The cron + short-script pair is Linux' universal scheduler: every minute, CPU load and temperature are appended to a CSV with built-in rotation. Zero dependencies, zero daemons, survives reboots on its own.

Hardware

An ODROID-M1 (Rockchip RK3568B2, 4 Cortex-A55, 4-8 GB) running Armbian or Ubuntu Hardkernel, with M.2 NVMe, SATA and gigabit Ethernet. None: readings come from the board itself.

Wiring

No wiring. Check cron (or cronie) is installed and running on the distribution you use.

How it works

cron runs the script on schedule; the script reads /proc and sysfs, appends a CSV line then truncates past 100,000 lines to bound storage.

Running it

On Armbian: apt install gpiod python3-gpiod; the RK3568’s two GPIO chips (gpiochip0/gpiochip3) show in gpiodetect, map the pin with gpioinfo.

Variants

Push the CSV to a server (curl -T), or replace cron with a systemd timer (OnUnitActiveSec=60) for integrated journalctl logs.

journal-cron.sh

#!/bin/bash
# Mesure ponctuelle appelee par cron (ici toutes les minutes).
# Installation :
#   sudo cp journal-cron.sh /usr/local/bin/mesure-cart.sh
#   sudo chmod +x /usr/local/bin/mesure-cart.sh
#   (crontab -e) puis :  * * * * * /usr/local/bin/mesure-cart.sh

JOURNAL="/var/log/mesure-cart.csv"
[ -f "$JOURNAL" ] || echo "horodatage,charge,temp_c" > "$JOURNAL"

# 1) Charge moyenne (1 minute) depuis /proc/loadavg
CHARGE=$(awk '{print $1}' /proc/loadavg)

# 2) Temperature SoC (tolere l'absence du capteur)
TEMP="NA"
for z in /sys/class/thermal/thermal_zone*/temp; do
  [ -r "$z" ] && TEMP=$(( $(cat "$z") / 1000 )) && break
done

# 3) Ligne CSV horodatee, append atomique
echo "$(date -Is),$CHARGE,$TEMP" >> "$JOURNAL"

# 4) Rotation maison : garder ~100 000 lignes (~70 jours a la minute)
if [ "$(wc -l < "$JOURNAL")" -gt 100000 ]; then
  tail -n 50000 "$JOURNAL" > "$JOURNAL.tmp" && mv "$JOURNAL.tmp" "$JOURNAL"
fi

← Back to the board