blob: 11962f9eaf19d8ac04891efd0308dfcb165feac6 [file] [log] [blame]
tome331eb42014-10-08 19:03:32 -07001#!/bin/bash
Pavlin Radoslavov91413792014-10-15 11:00:32 -07002# -----------------------------------------------------------------------------
tome331eb42014-10-08 19:03:32 -07003# Monitors selected set of ONOS commands using the system watch command.
Pavlin Radoslavov91413792014-10-15 11:00:32 -07004# -----------------------------------------------------------------------------
Ayaka Koshibef17f34a2015-09-24 19:31:48 -07005function _usage () {
6cat << _EOF_
7usage:
8 $(basename $0) [node] <commands> [watchflags]
9
10options:
11- [node] <commands> : the node to run the commands against
12- [watchflags] : flags to be passed to the watch command.
13
14summary:
15 Monitors selected set of ONOS commands using the system watch command.
16
17 <commands> is a comma-sepatarted list of ONOS CLI commands. If no commands
18 are supplied, the commands run are 'summary', 'intents', 'flows', and
19 'hosts' against \$OCI.
20
21 Note that [watchflags] only applies to platforms with the Linux-like watch
22 command. For other platforms, the default behavior of watch (refresh every 2
23 s) is emulated.
24
25_EOF_
26}
27
28[ "$1" = "-h" ] && _usage && exit 0
tome331eb42014-10-08 19:03:32 -070029
30[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
31. $ONOS_ROOT/tools/build/envDefaults
32
33node=${1:-$OCI}
34
35commands="${2:-summary,intents,flows,hosts}"
36
37aux=/tmp/onos-watch.$$
toma6897792014-10-08 22:21:05 -070038trap "rm -f $aux" EXIT
tome331eb42014-10-08 19:03:32 -070039
40echo "$commands" | tr ',' '\n' > $aux
Ayaka Koshibef17f34a2015-09-24 19:31:48 -070041
42# emulate watch if not Linux.
43if [ "$(uname)" != "Linux" ]; then
44 while clear; "onos $node -b <$aux 2>/dev/null" ; do sleep 2; done
45else
46 watch $3 "onos $node -b <$aux 2>/dev/null"
47fi