<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parsing the output of &amp;quot;mgmt_cli&amp;quot; in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99084#M5229</link>
    <description>&lt;P&gt;you put the quotes around the dot as well ( ".ipv4-address" ), but it needs to be after the dot: ."ipv4-address"&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2020 11:26:47 GMT</pubDate>
    <dc:creator>Norbert_Bohusch</dc:creator>
    <dc:date>2020-10-14T11:26:47Z</dc:date>
    <item>
      <title>Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1661#M5</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;When running a mgmt_cli command the output of the command is presented in text format.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Although Unix offers many tools for parsing text (e.g. cut, grep and awk), a better approach for parsing the output of mgmt_cli is to use &lt;A href="https://en.wikipedia.org/wiki/JSON"&gt;json format&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Once the output of the mgmt_cli command is in json, it is possible to use standard tools such as jq to do all the parsing work for you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;This document provides examples for using jq to handle the output of a mgmt_cli command.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;To learn more about jq, you can visit &lt;A href="https://stedolan.github.io/jq/" title="https://stedolan.github.io/jq/"&gt;https://stedolan.github.io/jq/&lt;/A&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://jqplay.org" rel="nofollow"&gt;https://jqplay.org&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;A href="https://jqplay.org/" title="https://jqplay.org/"&gt;https://jqplay.org/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Making mgmt_cli produce json instead of text output is easy. Simply add &lt;STRONG&gt;--format json&lt;/STRONG&gt; to your mgmt_cli command.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;mgmt_cli show host name "my host" --format json&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="; text-decoration: underline; font-size: 10.5pt;"&gt;&lt;STRONG&gt;Extract values from a mgmt_cli json response:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Extract the a top-level field&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-host name h1 --root true --format json | $CPDIR/jq/jq ".color"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"black"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Extract a field inside another field:&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-host name h1 --root true --format json | $CPDIR/jq/jq ".domain.name"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Extract a field that contains non-alphanumeric characters like “-“&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-package name Standard --root true --format json | $CPDIR/jq/jq '.["installation-targets"]'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"all"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Extract a field inside another field (both have hyphen in their name):&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-host name h1 --root true --format json | $CPDIR/jq/jq '.["meta-info"]["last-modifier"]'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"administrator1"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="; text-decoration: underline; font-size: 10.5pt;"&gt;&lt;STRONG&gt;Tip&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt; adding the “-r” parameter remove the quotation marks from the output:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-host name h1 --root true --format json | $CPDIR/jq/jq ".color"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; color: #2873ee;"&gt;"black"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-host name h1 --root true --format json | $CPDIR/jq/jq ".color" -r&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; color: #2873ee;"&gt;black&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="; text-decoration: underline; font-size: 10.5pt;"&gt;&lt;STRONG&gt;Working with arrays:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Get the array:&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-group name "My Group" --root true --format json | $CPDIR/jq/jq ".members"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "type": "group",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "IPs that should reach the sales application",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "2a83b2c4-8f82-41a4-9763-356e49c0947c"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "type": "host",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "h1",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "ce18c250-98c5-464e-94ff-04845e64a233"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "type": "host",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "h2",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "13faa04f-a6d8-4b72-aab7-33fadaf0f134"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Get the array elements (it would remove the [ ] around the array items and the commas between the items)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-group name "My Group" --root true --format json | $CPDIR/jq/jq ".members[]"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "type": "group",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "name": "IPs that should reach the sales application",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "uid": "2a83b2c4-8f82-41a4-9763-356e49c0947c"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "type": "host",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "name": "h1",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "uid": "ce18c250-98c5-464e-94ff-04845e64a233"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "domain": {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "domain-type": "domain",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "uid": "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "SMC User"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; },&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "type": "host",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "name": "h2",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "uid": "13faa04f-a6d8-4b72-aab7-33fadaf0f134"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Get a single field from every array element&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-group name "My Group" --root true --format json | $CPDIR/jq/jq ".members[].name"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"IPs that should reach the sales application"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"h1"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"h2"&lt;/SPAN&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Get a single field from every array element, key name contains a hyphen&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-package name standard --root true --format json | $CPDIR/jq/jq '.["access-layers"][].name'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"Network"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"my layer"&lt;/SPAN&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;Get multiple fields from every array element&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-group name "My Group" --root true --format json | $CPDIR/jq/jq ".members[] | [.name , .type] " &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "IPs that should reach the sales application",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "group"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "h1",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "host"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "h2",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;&amp;nbsp; "host"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Courier New';"&gt;mgmt_cli show-group name "My Group" --root true --format json | $CPDIR/jq/jq ".members[] | [.name , .type] | @csv" -r&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"IPs that should reach the sales application","group"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"h1","host"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2873ee;"&gt;"h2","host"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="; text-decoration: underline; font-size: 10.5pt;"&gt;&lt;STRONG&gt;Using jq in a bash script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the bash script below, you can see how to extract simple fields and arrays from a mgmt_cli command into bash variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#!/bin/bash&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#points to where jq is installed&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;JQ=${CPDIR}/jq/jq&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# login as root without providing credentials&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;mgmt_cli login --root true &amp;gt; id.txt&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# save the details of a host object called "h1" and save them to a file called "host_details.json"&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;mgmt_cli show host name h1 -s id.txt --format json &amp;gt; host_details.json&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# get some of the host's fields and store them as bash variables&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;HOST_NAME=$($JQ -r ".name" host_details.json)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;HOST_LAST_MODIFY_TIME=$($JQ -r '.["meta-info"]["last-modify-time"]["iso-8601"]' host_details.json)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;echo "host name: $HOST_NAME"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;echo "last modified: $HOST_LAST_MODIFY_TIME"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# Working with json arrays&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# MGMT_CLI_OUTPUT is a string with multiple lines. Each line contains a name of a group members.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# in this example the output of mgmt_cli is not sent to a file, instead it is passed to jq directly using a pipe.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;MGMT_CLI_OUTPUT="`mgmt_cli show group name "my group" -s id.txt --format json | $JQ ".members[].name | @sh" -r`"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# break the string into an array - each element of the array is a line in the original string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# there are simpler ways, but this way allows the names to contain spaces. Gaia's bash version is 3.x so readarray is not available&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;ARR=()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;while read -r line; do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; ARR+=("$line")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;done &amp;lt;&amp;lt;&amp;lt; "$MGMT_CLI_OUTPUT"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# print the elements in the array&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;for i in "${ARR[@]}"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; echo "$i"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# using bash variables in a jq expression&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;MEMBERS_COUNT=$(mgmt_cli show group name "my group" -s id.txt --format json | $JQ ".members | length")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;echo "number of members in the group: $MEMBERS_COUNT"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;COUNTER=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;while [ $COUNTER -lt $MEMBERS_COUNT ]; do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; MEMBER_NAME=$(mgmt_cli show group name "my group" -s id.txt --format json | $JQ ".members[$COUNTER].name")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; echo $MEMBER_NAME&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; let COUNTER=COUNTER+1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# sometime the jq expression includes the character ' which means that it will not handle the variable properly&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;GROUP_LAST_MODIFY_TIME=$(mgmt_cli show group name "my group" -s id.txt --format json | $JQ '.["meta-info"]["last-modify-time"]["iso-8601"]')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;echo&amp;nbsp; $GROUP_LAST_MODIFY_TIME&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# this will not work:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#key="iso-8601"&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#group_last_modify_time=$(mgmt_cli show group name "my group" -s id.txt --format json | $JQ '.["meta-info"]["last-modify-time"][$key]')&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# using jq's --arg option it is possible to define variables that can later be used inside the jq expression even if the expression is surrounded by&lt;/STRONG&gt; &lt;STRONG&gt;single quotes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;KEY="iso-8601"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;GROUP_LAST_MODIFY_TIME_WITH_VARIABLE=$(mgmt_cli show group name "my group" -s id.txt --format json | $JQ --arg myvar "$KEY" '.["meta-info"]["last-modify-time"][$myvar]')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;echo&amp;nbsp; $GROUP_LAST_MODIFY_TIME_WITH_VARIABLE&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jan 2016 12:10:05 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1661#M5</guid>
      <dc:creator>Uri_Bialik</dc:creator>
      <dc:date>2016-01-13T12:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1662#M6</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the examples above, it really helps understand some of the nuances.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Silly question regarding this section of the example code:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# Working with json arrays&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;#&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# MGMT_CLI_OUTPUT is a string with multiple lines. Each line contains a name of a group members.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# in this example the output of mgmt_cli is not sent to a file, instead it is passed to jq directly using a pipe.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;MGMT_CLI_OUTPUT="`mgmt_cli show group name "my group" -s id.txt --format json | $JQ ".members[].name | @sh" -r`"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# break the string into an array - each element of the array is a line in the original string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;# there are simpler ways, but this way allows the names to contain spaces. Gaia's bash version is 3.x so readarray is not available&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;ARR=()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;while read -r line; do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp; ARR+=("$line")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;done &amp;lt;&amp;lt;&amp;lt; "$MGMT_CLI_OUTPUT"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529; font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;# print the elements in the array&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;for i in "${ARR[@]}"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;&amp;nbsp; echo "$i"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-family: 'courier new', courier;"&gt;done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I played around with that to build a script that exports the members of all groups to a two column (group name, member name) CSV file to allow me to rebuild the group membership quickly from the CSV file.&amp;nbsp; The while loop section above is used to generate the array of groups, for subsequent processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running the code, the while loop operates in a closed system, and no output is visible until it completes, something that can take some time, based on number of groups defined, so it is not clear that anything is happening.&amp;nbsp; When the loop completes, it dumps any output and the proceeds to the output for loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tailored the while loop like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;ARR=()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;while read -r line; do&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ARR+=("$line")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo -n '.'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;done &amp;lt;&amp;lt;&amp;lt; "$MGMT_CLI_OUTPUT"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;echo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when it executes, you see nothing then it blasts out a line of dots equaling the number of groups read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a better way to achieve this type of feedback output that will actually display in real time, not postpartum?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2016 16:40:41 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1662#M6</guid>
      <dc:creator>Eric_Beasley</dc:creator>
      <dc:date>2016-06-30T16:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1663#M7</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very helpful - thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 May 2018 12:02:08 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/1663#M7</guid>
      <dc:creator>Sven_Glock</dc:creator>
      <dc:date>2018-05-11T12:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98810#M5216</link>
      <description>&lt;P&gt;What's the correct syntax to extract IP-Adresses? When I say&lt;BR /&gt;mgmt_cli show host name "mypc" --format json | jq ".ipv4-address", I get the error&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;error: address is not defined&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;.ipv4-address 1 compile error&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 05:03:39 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98810#M5216</guid>
      <dc:creator>Matthias_Kring</dc:creator>
      <dc:date>2020-10-12T05:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98811#M5217</link>
      <description>&lt;P&gt;Put "ipv4-address" in quotes.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 05:15:47 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98811#M5217</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2020-10-12T05:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98814#M5218</link>
      <description>&lt;P&gt;Hmm. As you can see above, it already &lt;EM&gt;is&lt;/EM&gt; in quotes.&lt;/P&gt;&lt;P&gt;This one works:&amp;nbsp;&amp;nbsp;jq '.["ipv4-address"]'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 06:33:32 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/98814#M5218</guid>
      <dc:creator>Matthias_Kring</dc:creator>
      <dc:date>2020-10-12T06:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99084#M5229</link>
      <description>&lt;P&gt;you put the quotes around the dot as well ( ".ipv4-address" ), but it needs to be after the dot: ."ipv4-address"&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 11:26:47 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99084#M5229</guid>
      <dc:creator>Norbert_Bohusch</dc:creator>
      <dc:date>2020-10-14T11:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99085#M5230</link>
      <description>&lt;P&gt;Sorry, but this doesn't work for me either:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;mgmt_cli show host name "mypc" --format json | jq ."ipv4-address"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;error: address is not defined&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;.ipv4-address 1 compile error&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 11:34:42 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99085#M5230</guid>
      <dc:creator>Matthias_Kring</dc:creator>
      <dc:date>2020-10-14T11:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99088#M5231</link>
      <description>&lt;P&gt;You need to include the jq filter in single quotes ' my_filter'&lt;/P&gt;
&lt;P&gt;like this&lt;/P&gt;
&lt;P&gt;mgmt_cli show host name "mypc" -r true --format json | jq &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;."ipv4-address"&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;'&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 11:59:58 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99088#M5231</guid>
      <dc:creator>Jim_Oqvist</dc:creator>
      <dc:date>2020-10-14T11:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing the output of "mgmt_cli"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99089#M5232</link>
      <description>&lt;P&gt;Sorry, you are right. My part is only relevant if it is part of a longer command like below (disconnect all WEB_API sessions):&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="de-AT"&gt;mgmt_cli -r true show sessions details-level full --format json | jq -r '.objects[] | select(."user-name"=="WEB_API")&amp;nbsp;| "mgmt_cli -r true disconnect uid " + .uid + " discard true"' | bash&lt;/P&gt;
&lt;P lang="de-AT"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P lang="de-AT"&gt;Here the outer quotes you mentioned are there but enclose the whole jq statement.&lt;/P&gt;
&lt;P lang="de-AT"&gt;PS: you don't need the brackets though&lt;/P&gt;
&lt;P lang="de-AT"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 12:06:45 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Parsing-the-output-of-quot-mgmt-cli-quot/m-p/99089#M5232</guid>
      <dc:creator>Norbert_Bohusch</dc:creator>
      <dc:date>2020-10-14T12:06:45Z</dc:date>
    </item>
  </channel>
</rss>

