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} |
DongRyeol Cha | 5c0a9f0 | 2018-05-17 14:32:55 +0900 | [diff] [blame^] | 12 | remote_scp=$ONOS_USER@[${remote:-$OCI}] |
Brian O'Connor | 0a53fac | 2015-03-19 22:21:18 -0700 | [diff] [blame] | 13 | message=$2 |
| 14 | |
| 15 | if [ -z "$message" ]; then |
| 16 | echo "Usage: onos-log-write <instance> <message>" |
| 17 | exit |
| 18 | fi |
| 19 | if [ -z $(which figlet) ]; then |
| 20 | echo "Install figlet; example: brew install figlet" |
| 21 | exit |
| 22 | fi |
| 23 | |
| 24 | #text=$(figlet $message) |
| 25 | #echo "Writing to $remote:" |
| 26 | #echo $text |
| 27 | #echo |
| 28 | |
| 29 | [ -n "$instance" ] && \ |
| 30 | LOG=$ONOS_INSTALL_DIR/$KARAF_DIST/instances/$instance/data/log/karaf.log || \ |
| 31 | LOG=$ONOS_INSTALL_DIR/log/karaf.log |
| 32 | |
| 33 | #broken by special chars like ` |
| 34 | #ssh -t $remote "sudo mkdir -p $(dirname $LOG) && echo $text | sudo tee -a $LOG" |
| 35 | |
| 36 | figlet $message > /tmp/message.txt |
DongRyeol Cha | 5c0a9f0 | 2018-05-17 14:32:55 +0900 | [diff] [blame^] | 37 | scp /tmp/message.txt $remote_scp:/tmp |
Brian O'Connor | 0a53fac | 2015-03-19 22:21:18 -0700 | [diff] [blame] | 38 | ssh -t $remote "sudo mkdir -p $(dirname $LOG) && cat /tmp/message.txt | sudo tee -a $LOG; rm /tmp/message.txt" |