Brian O'Connor | 0a53fac | 2015-03-19 22:21:18 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Writes block text into the remote ONOS log file on the specified node. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | . $ONOS_ROOT/tools/test/bin/find-node.sh |
| 9 | |
| 10 | remote=$(find_node $1) |
| 11 | remote=$ONOS_USER@${remote:-$OCI} |
| 12 | message=$2 |
| 13 | |
| 14 | if [ -z "$message" ]; then |
| 15 | echo "Usage: onos-log-write <instance> <message>" |
| 16 | exit |
| 17 | fi |
| 18 | if [ -z $(which figlet) ]; then |
| 19 | echo "Install figlet; example: brew install figlet" |
| 20 | exit |
| 21 | fi |
| 22 | |
| 23 | #text=$(figlet $message) |
| 24 | #echo "Writing to $remote:" |
| 25 | #echo $text |
| 26 | #echo |
| 27 | |
| 28 | [ -n "$instance" ] && \ |
| 29 | LOG=$ONOS_INSTALL_DIR/$KARAF_DIST/instances/$instance/data/log/karaf.log || \ |
| 30 | LOG=$ONOS_INSTALL_DIR/log/karaf.log |
| 31 | |
| 32 | #broken by special chars like ` |
| 33 | #ssh -t $remote "sudo mkdir -p $(dirname $LOG) && echo $text | sudo tee -a $LOG" |
| 34 | |
| 35 | figlet $message > /tmp/message.txt |
| 36 | scp /tmp/message.txt $remote:/tmp |
| 37 | ssh -t $remote "sudo mkdir -p $(dirname $LOG) && cat /tmp/message.txt | sudo tee -a $LOG; rm /tmp/message.txt" |