Browse Source

[Improve][rootfs][crontab]

2021.03.08 / Folus Wen

Actions:
1. Add /usr/bin/run_log_clear.sh for clear /Storage/System & /Storage/OCPP log files.
2. Daily auto clear six month ago log file by crontab.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 years ago
parent
commit
2aff793efa
2 changed files with 29 additions and 0 deletions
  1. 28 0
      EVSE/rootfs/usr/bin/run_log_clear.sh
  2. 1 0
      EVSE/rootfs/var/spool/cron/crontabs/root

+ 28 - 0
EVSE/rootfs/usr/bin/run_log_clear.sh

@@ -0,0 +1,28 @@
+#!/bin/sh
+if [ $# -lt 2 ]; then
+        echo "Usage:  run_log_clear.sh [start month before] [end month before]"
+        echo "        start month >= 6 at least"
+        echo "        end month > start month"
+        echo "Sample: run_log_clear.sh 6 12 "
+        echo "        (Clear log before now 6 to 12 month)"
+        exit 0;
+else
+        if [ "$2" -lt "$1" ]
+        then
+                echo "Usage:  run_log_clear.sh [start month before] [end month before]"
+                echo "        start month >= 6 at least"
+                echo "        end month > start month"
+                exit 0
+        fi
+
+        for idx in $(seq $1 $2)
+        do
+                now=$(( `date +%s`-(($idx*30)*86400)))
+                target=`date -D '%s' +%Y.%m -d "$now"`
+                echo $target
+                `/bin/rm -f /Storage/System/[$target\]*`
+                `/bin/rm -f /Storage/OCPP/[$target\]*`
+        done
+
+fi
+

+ 1 - 0
EVSE/rootfs/var/spool/cron/crontabs/root

@@ -23,3 +23,4 @@
 0 0 * * * cat "" > /Storage/SystemLog/check_tmate.log
 #* * * * * /usr/bin/check_tmate.sh >> /Storage/SystemLog/check_tmate.log 2>&1
 0 * * * * /sbin/logrotate /etc/logrotate.conf
+0 1 * * * /usr/bin/run_log_clear.sh 6 18