blob: 53129bcf7e40346946179f903fceec0f2e656e49 [file] [log] [blame]
Jordan Halterman795e4922018-08-06 12:11:20 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Collect Atomix 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 Atomix 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
33 nodes=$(env | sort | egrep "^OCC[0-9]+" | cut -d= -f2)
34else
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
Jordan Halterman795e4922018-08-06 12:11:20 -070053 mkdir -p ${node}
Jon Hall27e94e42019-01-08 16:17:24 -080054 if [ "$USE_RSYNC" = "true" ]; then
55 rsync -avhz --progress [$ONOS_USER@${node}]:$ATOMIX_INSTALL_DIR/log/atomix.log* ./${node}/
56 else
57 scp -p $ONOS_USER@[${node}]:$ATOMIX_INSTALL_DIR/log/atomix.log* ./${node}/
58 fi
Jordan Halterman795e4922018-08-06 12:11:20 -070059done