Files
Alpine_5G/scripts/rotate-5g-log.sh
nearxos 160ad641ce Add web GUI, docs, scripts, and 5G router config
- Web app (Flask): status, config, firewall, logs, users, restart
- Docs: AT commands, deploy, DNS, quickstart, web GUI
- Scripts: connect, deploy, diag, healthcheck, modem-status, speedtest, status, troubleshoot
- Init and iptables: 5g-router, 5g-webgui, rules.v4
- CHANGELOG, TODO, REVISION; config and README updates
2026-02-02 09:38:23 +02:00

22 lines
696 B
Bash

#!/bin/sh
# Rotate /var/log/5g-router.log (keep last 5 copies, max 1MB each)
# Run from cron daily: 0 3 * * * /usr/local/bin/rotate-5g-log.sh
# Alpine does not ship logrotate by default; this is a minimal alternative.
# Rev: 1 (see REVISION in repo root)
LOG="/var/log/5g-router.log"
MAXSIZE=$((1024 * 1024)) # 1MB
KEEP=5
[ ! -f "$LOG" ] && exit 0
size=$(stat -c %s "$LOG" 2>/dev/null) || size=$(wc -c < "$LOG" 2>/dev/null) || exit 0
[ "$size" -lt "$MAXSIZE" ] && exit 0
for i in $(seq $((KEEP - 1)) -1 1); do
[ -f "${LOG}.$i" ] && mv "${LOG}.$i" "${LOG}.$((i+1))"
done
[ -f "${LOG}.1" ] && mv "${LOG}.1" "${LOG}.2"
mv "$LOG" "${LOG}.1"
touch "$LOG"
chmod 644 "$LOG" 2>/dev/null || true