From 8c5c168c737eac679dd1d65a8ffe184424f5d55a Mon Sep 17 00:00:00 2001 From: Adam Olech Date: Tue, 22 Dec 2020 23:46:37 +0000 Subject: [PATCH] Add script for getting qemu ip --- virt/get_ip.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 virt/get_ip.sh diff --git a/virt/get_ip.sh b/virt/get_ip.sh new file mode 100755 index 00000000000..afe41e72981 --- /dev/null +++ b/virt/get_ip.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -e + +cd $(dirname $0) + +WORKDIR=$(realpath work) + +Q2=$WORKDIR/qemu_mon +MIN=$Q2.in +MOUT=$Q2.out + +LINE="" + +function flushPipe() { + # Ensure there is no lingering output in the pipe + # by flushing it in a slightly hacky way. + # dd complains about resource not being available.... + # dd: error reading 'work/qemu_mon.out': Resource temporarily unavailable + # ...but it doesn't matter. + (dd if=$MOUT iflag=nonblock of=/dev/null || true) >/dev/null 2>&1 +} + +flushPipe + +echo 'info network' > $MIN + +# Reading twice cause first line is echoed command. +read LINE < $MOUT +read LINE < $MOUT + +flushPipe + +MAC=$(echo $LINE | cut -d "," -f4 | cut -d "=" -f2) + +echo $MAC