Skip to content

Commit

Permalink
Add script for getting qemu ip
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamOlech committed Jul 27, 2021
1 parent ce41a23 commit 8c5c168
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions virt/get_ip.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8c5c168

Please sign in to comment.