Mike Q
Mike Q

Reputation: 7327

List the available KVMs on Linux with a script

I want to take the following "Names" from this command and put them in an array for a bash script, any ideas on the best way to do this?

    $ virsh -r -c qemu:///system list --all

     Id    Name                           State
    ----------------------------------------------------
    3     KVM_Win7-KVM                   running

EDIT:

The final result was this:

  declare -a kvm_list=( $(virsh -r -c qemu:///system list --all --name) )

Upvotes: 1

Views: 349

Answers (1)

larsks
larsks

Reputation: 311703

First consider using the --name option to virsh --list, so you end up with:

virsh -r -c qemu:///system list --all --name

And then reading output of command into array in bash

Upvotes: 2

Related Questions