Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Virsh list all in json: Difference between revisions

From John's Wiki
Created page with "The following <code>bash</code> command will list all virsh guests in json. echo "[ $(virsh list --all|grep -Ev 'Id|----'|awk '{print "{ \"id\": \""$1"\", \"name\": \""$2"\", \"state\": \""$3 $4"\"}," }'|head -n -1) {} ]"|jq -r Output example: <pre> [ { "id": "38", "name": "Mac", "state": "running" }, { "id": "39", "name": "Dennis", "state": "running" }, { "id": "40", "name": "Charlie", "state": "running" }, ... </pre>"
 
No edit summary
Line 1: Line 1:
The following <code>bash</code> command will list all virsh guests in json.
The following <code>bash</code> command will list all virsh guests in json.


echo "[ $(virsh list --all|grep -Ev 'Id|----'|awk '{print "{ \"id\": \""$1"\", \"name\": \""$2"\", \"state\": \""$3 $4"\"}," }'|head -n -1) {} ]"|jq -r
<syntaxhighlight lang="bash" line>
echo "[ $(virsh list --all|grep -Ev 'Id|----'|awk '{print "{ \"id\": \""$1"\", \"name\": \""$2"\", \"state\": \""$3 $4"\"}," }'|head -n -1) {} ]"|jq -r
</syntaxhighlight>


Output example:
Output example:


<pre>
<syntaxhighlight lang="json" line>
[
[
   {
   {
Line 23: Line 25:
   },
   },
...
...
</pre>
</syntaxhighlight>

Revision as of 21:42, 28 November 2024

The following bash command will list all virsh guests in json.

echo "[ $(virsh list --all|grep -Ev 'Id|----'|awk '{print "{ \"id\": \""$1"\", \"name\": \""$2"\", \"state\": \""$3 $4"\"}," }'|head -n -1) {} ]"|jq -r

Output example:

[
  {
    "id": "38",
    "name": "Mac",
    "state": "running"
  },
  {
    "id": "39",
    "name": "Dennis",
    "state": "running"
  },
  {
    "id": "40",
    "name": "Charlie",
    "state": "running"
  },
...