1 #!/bin/bash 2 3 CSV=FALSE 4 5 while getopts "c" name 6 do 7 case $name in 8 c) CSV=TRUE;; 9 esac 10 done 11 shift $(( OPTIND - 1 )) 12 13 if [ $# -gt 1 ] 14 then 15 echo "usage: $(basename $0) [ <options> ] [ <filename> ]" >&2 16 echo "options: -c for CSV format" >&2 17 exit 1 18 fi 19 20 # If the -c option is called, the option index is shifted over once and the 21 # value of the option is stored in $FILE. The default behavior is that the sed 22 # transform will read from standard input if no argument is provided and $FILE 23 # will be empty. 24 FILE=$1 25 26 SED_SCRIPT=" 27 s/ CHROMEOS_RELEASE_VERSION=[^ ]*// 28 s/ BOARD=[^ ]*// 29 " 30 31 if [ $CSV = "TRUE" ] 32 then 33 echo "Location,Status,Fixed,Comments" 34 SED_SCRIPT=" 35 s/ ...[A-Z]*// 36 $SED_SCRIPT 37 s/ /,/ 38 s/$/,,/ 39 " 40 sed "$SED_SCRIPT" $FILE 41 42 else 43 SED_SCRIPT=" 44 s/^[^ ]* ...[A-Z]* // 45 $SED_SCRIPT 46 s/is up/servod &/ 47 s/.*pwr_button:press.*/power button is stuck down/ 48 s/^\(not running servod\) \(not running brillo\)$/\1, \2/ 49 s/^not running servod$/up but not running servod, reason unknown/ 50 s/^servod not configured$/running brillo, BOARD for &/ 51 s/^servod failed$/servod running, but not working/ 52 s/^is down/no answer to ping/ 53 s/^\(not running servod\) \(ssh is down\)$/\1, ping is up, \2/ 54 " 55 sed "$SED_SCRIPT" $FILE | sort | uniq -c | 56 awk '{ print ; sum += $1 } END { printf "%7d total\n", sum }' | 57 sort | cut -c -72 58 fi 59