Commit Diff


commit - 23c8c9a930a6532b06ce5059e8702389d0b0d19e
commit + bbf6fbc3acc869e421c3c9128b1e1fc5e5fee561
blob - cb42a354aedfbb3ca532f9f7584712ee57da0a5c
blob + 1d5c52966c271c3813f652781af899a4111c2796
--- vdcron
+++ vdcron
@@ -17,19 +17,21 @@ TEMP=$(mktemp)
 FILE=
 VERSION=0.7.1
 CONTEXT="cli"
+LOG_SIZE=1000
 USAGE="$0 <options> [context]
       options are:
-        -h        : this help
-        -d        : debug
-        -s <value>: force an initial sleep different than the default: $SLEEP seconds
-        -f <file> : use a specific input file
+        -h          : this help
+        -d          : debug
+        -s <integer>: force an initial sleep different than the default: $SLEEP seconds
+        -f <file>   : use a specific input file
+        -l <integer>: max log size in lines we keep
       context:
         Context is just an optional name allowing you to to retreive this information in the logs. 
         This is useful just to know what has been trigered vdcron (cron, apm-resume, ...)
         By default the value is \"cmd line\"
       You are running $0 version $VERSION
         "
-PARAMS="hdf:s:"
+PARAMS="hdf:s:l:"
 
 while getopts "$PARAMS" optchar; do
     case "$optchar" in 
@@ -50,6 +52,12 @@ while getopts "$PARAMS" optchar; do
         h) echo "$USAGE"
             exit 0
             ;;
+        l) LOG_SIZE=$OPTARG
+            if [ ! "$LOG_SIZE" -gt "0" ]; then
+                echo "Not a valid log size value: $LOG_SIZE"
+                exit 1
+            fi
+            ;;
         \?) #echo "Invalid argument: $OPTARG"
             exit 1
             ;;
@@ -233,3 +241,7 @@ done < $FILE
 mv "$TEMP" "$FILE"
 chmod 600 "$FILE"
 echo "finished on $(date)" >> "$LOG"
+
+if [ "$(($(cat $LOG | wc -l )))" -gt "$LOG_SIZE" ];then 
+    printf "1,-${LOG_SIZE}d\nwq\n" | ed -s "$LOG"
+fi