Jordan Halterman | 795e492 | 2018-08-06 12:11:20 -0700 | [diff] [blame] | 1 | #!/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 | |
| 9 | function 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 |
| 26 | if [ "${1}" = "-h" -o "${1}" = "--help" ]; then |
| 27 | print_usage |
| 28 | exit 0 |
| 29 | fi |
| 30 | |
| 31 | # Select the target |
| 32 | if [ "${1}" = "--cell" ]; then |
| 33 | nodes=$(env | sort | egrep "^OCC[0-9]+" | cut -d= -f2) |
| 34 | else |
| 35 | nodes=${1:-$OCI} |
| 36 | fi |
| 37 | |
| 38 | # Execute the remote commands |
| 39 | for node in $nodes; do |
| 40 | echo "fetching from ${node}..." |
Jon Hall | 27e94e4 | 2019-01-08 16:17:24 -0800 | [diff] [blame^] | 41 | 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 Halterman | 795e492 | 2018-08-06 12:11:20 -0700 | [diff] [blame] | 53 | mkdir -p ${node} |
Jon Hall | 27e94e4 | 2019-01-08 16:17:24 -0800 | [diff] [blame^] | 54 | 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 Halterman | 795e492 | 2018-08-06 12:11:20 -0700 | [diff] [blame] | 59 | done |