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