- /nfc/README.md - /nfc/clean_old_logs.sh - /nfc/clockin.py - /nfc/emptycards.py - /nfc/sync_clocks.sh - /piservices/Dockerfile - /piservices/Portainer-lamp-stack.env - /piservices/Portainer-lamp-stack.yaml - /piservices/README.md - /piservices/avahi-alias.service - /piservices/clockpy.service - /piservices/emptycards.service - /piservices/nfc-sync.service - /piservices/test.sh - /www/404 - /www/get-table-data.php - /www/habiwan copy.png - /www/habiwan.png - /www/index.php - /www/log_swipe.php - /www/manage_data.php - /www/manifest.json - /www/names.csv - /www/network_audit.csv - /www/network-tracker.html - /www/nfc_debug.log - /www/scanner.html - /www/staff_names.php - /www/times.csv - /www/check_update.php - /www/dev.php - /www/favicon.png - /www/JsBarcode.all.min.js - /www/README.md
26 lines
765 B
Bash
26 lines
765 B
Bash
#!/bin/bash
|
|
# added sudo crontab to the pi to trim old data at 2 am:
|
|
# 0 2 * * * /bin/bash /home/YOURPIUSER/nfc/clean_old_logs.sh >/dev/null 2>&1
|
|
|
|
TIMES_FILE="/home/YOURPIUSER/nfc/times.csv"
|
|
|
|
# 1. Get the date 6 months ago (for testing)
|
|
LOG_CUTOFF=$(date -d "6 months ago" +%Y-%m-%d)
|
|
|
|
# 2. Filter using universally compatible literal matching
|
|
awk -v cutoff="$LOG_CUTOFF" '
|
|
{
|
|
if (match($0, /[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
|
|
date_part = substr($0, RSTART, RLENGTH)
|
|
if (date_part < cutoff) {
|
|
next
|
|
}
|
|
}
|
|
print $0
|
|
}' "$TIMES_FILE" > "${TIMES_FILE}.tmp"
|
|
|
|
# 3. Safely replace the file
|
|
mv "${TIMES_FILE}.tmp" "$TIMES_FILE"
|
|
|
|
# 4. Force the sync script to grab the new file inode
|
|
systemctl restart nfc-sync.service |