tom | e331eb4 | 2014-10-08 19:03:32 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
tom | e331eb4 | 2014-10-08 19:03:32 -0700 | [diff] [blame] | 3 | # Monitors selected set of ONOS commands using the system watch command. |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame^] | 5 | function _usage () { |
| 6 | cat << _EOF_ |
| 7 | usage: |
| 8 | $(basename $0) [node] <commands> [watchflags] |
| 9 | |
| 10 | options: |
| 11 | - [node] <commands> : the node to run the commands against |
| 12 | - [watchflags] : flags to be passed to the watch command. |
| 13 | |
| 14 | summary: |
| 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 |
tom | e331eb4 | 2014-10-08 19:03:32 -0700 | [diff] [blame] | 29 | |
| 30 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 31 | . $ONOS_ROOT/tools/build/envDefaults |
| 32 | |
| 33 | node=${1:-$OCI} |
| 34 | |
| 35 | commands="${2:-summary,intents,flows,hosts}" |
| 36 | |
| 37 | aux=/tmp/onos-watch.$$ |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 38 | trap "rm -f $aux" EXIT |
tom | e331eb4 | 2014-10-08 19:03:32 -0700 | [diff] [blame] | 39 | |
| 40 | echo "$commands" | tr ',' '\n' > $aux |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame^] | 41 | |
| 42 | # emulate watch if not Linux. |
| 43 | if [ "$(uname)" != "Linux" ]; then |
| 44 | while clear; "onos $node -b <$aux 2>/dev/null" ; do sleep 2; done |
| 45 | else |
| 46 | watch $3 "onos $node -b <$aux 2>/dev/null" |
| 47 | fi |