blob: 5b8ccca30ec8fa1abb484d7dfe468173d5433f68 [file] [log] [blame]
Yuta HIGUCHId89cc9d2014-12-09 11:52:25 -08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Collect ONOS logs from a single node or the current ONOS cell.
4# -----------------------------------------------------------------------------
5
6[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
8
9function print_usage {
10 command_name=`basename $0`
11 echo "Collect ONOS logs from a single node or the current ONOS cell."
12 echo
13 echo "Usage: $command_name <TARGET> "
14 echo " $command_name [-h | --help]"
15 echo "Options:"
16 echo " TARGET The target of the command"
17 echo " [-h | --help] Print this help"
18 echo ""
19 echo "TARGET: <hostname | --cell>"
20 echo " hostname Execute on the specified host name"
21 echo " --cell Execute on the current ONOS cell"
22 echo ""
23}
24
25# Print usage
26if [ "${1}" = "-h" -o "${1}" = "--help" ]; then
27 print_usage
28 exit 0
29fi
30
31# Select the target
32if [ "${1}" = "--cell" ]; then
Claudine Chiu45312d02016-06-15 13:17:12 +000033 nodes=$(env | sort | egrep "^OC[0-9]+" | cut -d= -f2)
Yuta HIGUCHId89cc9d2014-12-09 11:52:25 -080034else
35 nodes=${1:-$OCI}
36fi
37
38# Execute the remote commands
39for node in $nodes; do
40 echo "fetching from ${node}..."
Jon Hall27e94e42019-01-08 16:17:24 -080041 USE_RSYNC=${USE_RSYNC:-'false'}
42 # Check if RSYNC is installed
43 if [ "$USE_RSYNC" = "true" ]; then
44 if ssh $ONOS_USER@${node} $SSH_OPTIONS which rsync >&2 > /dev/null; then
45 echo "Using rsync"
46 else
47 echo "Installing rsync"
48 # TODO check remote OS and use proper method to install rsync
49 ssh $ONOS_USER@${node} sudo apt-get install -y rsync || USE_RSYNC='false'
50 fi
51 fi
52
Yuta HIGUCHId89cc9d2014-12-09 11:52:25 -080053 mkdir -p ${node}
Jon Hall27e94e42019-01-08 16:17:24 -080054 if [ "$USE_RSYNC" = "true" ]; then
55 rsync -avhz --progress [$ONOS_USER@${node}]:$ONOS_INSTALL_DIR/log/karaf.log* ./${node}/
56 else
57 scp -p $ONOS_USER@[${node}]:$ONOS_INSTALL_DIR/log/karaf.log* ./${node}/
58 fi
Yuta HIGUCHId89cc9d2014-12-09 11:52:25 -080059done