J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 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 ] |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 14 | then |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 15 | echo "usage: $(basename $0) [ <options> ] [ <filename> ]" >&2 |
| 16 | echo "options: -c for CSV format" >&2 |
| 17 | exit 1 |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 18 | fi |
| 19 | |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 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. |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 24 | FILE=$1 |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 25 | |
| 26 | SED_SCRIPT=" |
J. Richard Barnette | 3d333e6 | 2014-07-14 14:34:23 -0700 | [diff] [blame] | 27 | s/ CHROMEOS_RELEASE_VERSION=[^ ]*// |
| 28 | s/ BOARD=[^ ]*// |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 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 | |
J. Richard Barnette | 3d333e6 | 2014-07-14 14:34:23 -0700 | [diff] [blame] | 56 | awk '{ print ; sum += $1 } END { printf "%7d total\n", sum }' | |
| 57 | sort | cut -c -72 |
Troy Kensinger | 1e31114 | 2014-09-19 15:41:18 -0700 | [diff] [blame] | 58 | fi |