[Qa-jenkins-scm] [Git][qa/jenkins.debian.net][master] djm-logparser: refactor, use printf

Holger Levsen (@holger) gitlab at salsa.debian.org
Mon Apr 3 22:07:52 BST 2023



Holger Levsen pushed to branch master at Debian QA / jenkins.debian.net


Commits:
7c680bfb by Holger Levsen at 2023-04-03T23:07:43+02:00
djm-logparser: refactor, use printf

Signed-off-by: Holger Levsen <holger at layer-acht.org>

- - - - -


1 changed file:

- bin/djm-logparser


Changes:

=====================================
bin/djm-logparser
=====================================
@@ -17,38 +17,43 @@ set -o pipefail		# see eg http://petereisentraut.blogspot.com/2010/11/pipefail.h
 
 LOGFILE=~/.djm.log
 LOGMONTH="$(date -u '+%Y-%m')"
+THREE_C="%42s  %6s  %12s\n"
+TWO_C="%42s  %6s\n"
+seperator() {
+	echo "----------------------------------------------------------------"
+}
 
 #
 # main
 #
 
+HOSTS=$(cut -d ',' -f2 $LOGFILE | sort -u | wc -l)
 TOTAL=$(grep -c $LOGMONTH $LOGFILE)
 HOURS=$(cut -b 1-13 $LOGFILE | sort -u | wc -l)
-HOSTS=$(cut -d ',' -f2 $LOGFILE | sort -u | wc -l)
 ACTIONS=$(cut -d ',' -f3 $LOGFILE |sort -u|sed -s "s# #_#g")
 REASONS=$(cut -d ',' -f4 $LOGFILE |sort -u|sed -s "s# #_#g")
 
 echo "Still very simple statistics for djm logs at $LOGFILE in $LOGMONTH"
 echo
-echo "Amount of djm actions done:		$TOTAL"
-echo "Amount of hours with djm usage:		$HOURS"
-echo "Amount of hosts maintained:		$HOSTS"
-echo "----------------------------------------------------"
+printf "$TWO_C" "hosts maintained:" "$HOSTS"
+printf "$TWO_C" "djm actions done:" "$TOTAL"
+printf "$TWO_C" "hours with djm usage:" "$HOURS"
+seperator
 
 for action in $ACTIONS ; do
 	grep_action="$(echo $action | sed -s 's#_# #g' | xargs echo)"
 	AMOUNT=$(cut -d ',' -f3 $LOGFILE |grep "$grep_action"|wc -l)
 	PERCENT=$(echo "scale=2 ; $AMOUNT/$TOTAL*100"|bc||echo 0)
-	echo "Amount of $grep_action actions done:		$AMOUNT / $TOTAL = $PERCENT%"
+	printf "$THREE_C" "$grep_action actions done:" "$PERCENT%" "($AMOUNT / $TOTAL)"
 done
-echo "----------------------------------------------------"
+seperator
 
 for reason in $REASONS ; do
 	grep_reason="$(echo $reason | sed -s 's#_# #g' | xargs echo)"
 	AMOUNT=$(cut -d ',' -f4 $LOGFILE |grep "$grep_reason"|wc -l)
 	PERCENT=$(echo "scale=2 ; $AMOUNT/$TOTAL*100"|bc||echo 0)
-	echo "Amount of $grep_reason reasons done:		$AMOUNT / $TOTAL = $PERCENT%"
+	printf "$THREE_C" "$grep_reason reasons done:" "$PERCENT%" "($AMOUNT / $TOTAL)"
 done
-echo "----------------------------------------------------"
+seperator
 
 # todo: sort actions and reasons by highest amount



View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/commit/7c680bfb844864969028a56b11033110d543ff11

-- 
View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/-/commit/7c680bfb844864969028a56b11033110d543ff11
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/qa-jenkins-scm/attachments/20230403/93251cc7/attachment-0001.htm>


More information about the Qa-jenkins-scm mailing list