| #!/bin/bash | |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| ### Listen for logs | |
| ## usage: fx syslog [-d|--device <device>] [log-listener flags] | |
| ## | |
| ## Creates an SSH connection with a device and starts listening for logs. | |
| ## Pass -h to get help with log-listener flags. | |
| ## | |
| ## Arguments: | |
| ## -d|--device Fuchsia link-local name of the device. If not | |
| ## specified, will connect to the only available | |
| ## device on the link-local network. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh | |
| function listen { | |
| trap "exit 0" INT | |
| while true; do | |
| addr=$(fx-command-run netaddr --fuchsia "${device}") | |
| if [[ $? -eq 0 ]]; then | |
| echo "Connecting to device..." | |
| (fx-command-exec ssh "${addr}" /system/bin/log_listener "$@" || true) | |
| echo "Connection lost, looking for device" | |
| fi | |
| sleep 1 | |
| done | |
| } | |
| case $1 in | |
| -d|--device) | |
| shift # name | |
| if [[ -z "$1" ]]; then | |
| echo "Missing parameter: <device>" >&2 | |
| fx-command-help | |
| exit 1 | |
| fi | |
| device="$1" | |
| shift # value | |
| ;; | |
| esac | |
| echo "Looking for device" | |
| listen |