-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathilom-console-history
executable file
·105 lines (80 loc) · 2.02 KB
/
ilom-console-history
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#! /bin/sh
#
# WARNING: This utility depends on the `ilom-address` script, which
# you MUST customize to your cluster environment.
#
PROG="$(basename $0)"
## defaults
lines=25
## usage and version text
usage () {
cat <<EOF
Usage: $PROG [options] [HOST ...]
Show the last lines output to the ILOM SP serial console.
Options:
--all, -A Show the whole recorded console history.
(May be very long!)
--lines, -n NUM
Only show the last NUM lines (default: $lines).
--help, -h Print this help text.
EOF
}
## helper functions
die () {
rc="$1"
shift
(echo -n "$PROG: ERROR: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
exit $rc
}
warn () {
(echo -n "$PROG: WARNING: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
}
have_command () {
type "$1" >/dev/null 2>/dev/null
}
require_command () {
if ! have_command "$1"; then
die 1 "Could not find required command '$1' in system PATH. Aborting."
fi
}
is_absolute_path () {
expr match "$1" '/' >/dev/null 2>/dev/null
}
## parse command-line
short_opts='an:h'
long_opts='all,lines:,help'
if [ "x$(getopt -T)" != 'x--' ]; then
# GNU getopt
args=$(getopt --name "$PROG" --shell sh -l "$long_opts" -o "$short_opts" -- "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$PROG --help' to get usage information."
fi
# use 'eval' to remove getopt quoting
eval set -- $args
else
# old-style getopt, use compatibility syntax
args=$(getopt "$short_opts" "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$PROG --help' to get usage information."
fi
set -- $args
fi
while [ $# -gt 0 ]; do
case "$1" in
--all|-a) lines=0 ;;
--lines|-n) lines="$2"; shift ;;
--help|-h) usage; exit 0 ;;
--) shift; break ;;
esac
shift
done
var=$1
## main
require_command ssh
for host in "$@"; do
echo "==== ${host} ===="
echo -e "set /HOST/console line_count=${lines}\nshow /HOST/console/history\nexit" \
| ssh -T $(ilom-address "$host")
done