<?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: run-script output in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2837#M215</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marc,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, it is possible to retrieve output from &lt;STRONG&gt;run-script&lt;/STRONG&gt; API command. It's returned being encoded to base64 inside the &lt;STRONG&gt;show-task&lt;/STRONG&gt; API command response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Getting run-script output through HTTP request&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;​Run &lt;STRONG&gt;run-script &lt;/STRONG&gt;command (it's asynchronous) and save the &lt;STRONG&gt;task-id&lt;/STRONG&gt; from the response.&lt;/LI&gt;&lt;LI&gt;Run &lt;STRONG&gt;show-task&lt;/STRONG&gt; command providing &lt;STRONG&gt;task-id&lt;/STRONG&gt; that was saved in step 1. You have to run &lt;STRONG&gt;show-task&lt;/STRONG&gt; command several times until response will contain status "succeeded". You have to run &lt;STRONG&gt;show-task&lt;/STRONG&gt; with details-level set to "full".&lt;/LI&gt;&lt;LI&gt;Parse show-task response and extract the base64 encoded result by following path &lt;STRONG&gt;showTaskResult.tasks[0]["task-details"][0].responseMessage&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Decode the base64 encoded result (In Javascript it can be done with &lt;STRONG&gt;atob&lt;/STRONG&gt; function).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Getting run-script output through mgmt_cli tool (full example)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;mgmt_cli -r true run-script script-name "list root" script "ls -l /" targets.1 "my-management" --format json 2&amp;gt; /dev/null \&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' \&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| base64 -di&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Useful links&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/run-script"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/run-script&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/show-task"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/show-task&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#mgmt_cli"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#mgmt_cli&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#ws"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#ws&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Nov 2016 06:45:37 GMT</pubDate>
    <dc:creator>Eugene_Grybinny</dc:creator>
    <dc:date>2016-11-10T06:45:37Z</dc:date>
    <item>
      <title>run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2835#M213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can we retreive output for run-script API command ?&lt;/P&gt;&lt;P&gt;I can see result on Dashboard but it's possible to have this by API ?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Nov 2016 10:35:28 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2835#M213</guid>
      <dc:creator>Marc_Guyard</dc:creator>
      <dc:date>2016-11-09T10:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2836#M214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've find the solution.&lt;/P&gt;&lt;P&gt;Get task with full details :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; "task-id" : "29118dcb-d3e2-4096-a8ad-e3e2451db891",&lt;/P&gt;&lt;P&gt;&amp;nbsp; "details-level" : "full"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you have in responseMessage field the output in base64.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Nov 2016 10:42:36 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2836#M214</guid>
      <dc:creator>Marc_Guyard</dc:creator>
      <dc:date>2016-11-09T10:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2837#M215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marc,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, it is possible to retrieve output from &lt;STRONG&gt;run-script&lt;/STRONG&gt; API command. It's returned being encoded to base64 inside the &lt;STRONG&gt;show-task&lt;/STRONG&gt; API command response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Getting run-script output through HTTP request&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;​Run &lt;STRONG&gt;run-script &lt;/STRONG&gt;command (it's asynchronous) and save the &lt;STRONG&gt;task-id&lt;/STRONG&gt; from the response.&lt;/LI&gt;&lt;LI&gt;Run &lt;STRONG&gt;show-task&lt;/STRONG&gt; command providing &lt;STRONG&gt;task-id&lt;/STRONG&gt; that was saved in step 1. You have to run &lt;STRONG&gt;show-task&lt;/STRONG&gt; command several times until response will contain status "succeeded". You have to run &lt;STRONG&gt;show-task&lt;/STRONG&gt; with details-level set to "full".&lt;/LI&gt;&lt;LI&gt;Parse show-task response and extract the base64 encoded result by following path &lt;STRONG&gt;showTaskResult.tasks[0]["task-details"][0].responseMessage&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Decode the base64 encoded result (In Javascript it can be done with &lt;STRONG&gt;atob&lt;/STRONG&gt; function).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Getting run-script output through mgmt_cli tool (full example)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;mgmt_cli -r true run-script script-name "list root" script "ls -l /" targets.1 "my-management" --format json 2&amp;gt; /dev/null \&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' \&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| base64 -di&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Useful links&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/run-script"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/run-script&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/show-task"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#web/show-task&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#mgmt_cli"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#mgmt_cli&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/R80/APIs/index.html#ws"&gt;https://sc1.checkpoint.com/documents/R80/APIs/index.html#ws&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2016 06:45:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2837#M215</guid>
      <dc:creator>Eugene_Grybinny</dc:creator>
      <dc:date>2016-11-10T06:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2838#M216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey &lt;A href="https://community.checkpoint.com/migrated-users/47511"&gt;Robert Decker&lt;/A&gt;‌ can you update the above example for R80.10/R80.20.M1?&lt;/P&gt;&lt;P&gt;When I try to run something like:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;mgmt_cli -r true show-task task-id 0490542b-e741-40b9-be65-45e1e00c9f79 details-level full --format json | $CPDIR/jq/jq -r '(.tasks[0]["task-details"].responseMessage)' | base64 -di&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;I get:&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;SPAN class=""&gt;jq: error: Cannot index array with string&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2018 23:06:11 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2838#M216</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2018-07-31T23:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2839#M217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dameon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tasks-details is an objects list so try this command :&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;SPAN style="color: #333333; background-color: #f6f6f6;"&gt;mgmt_cli -r true show-task task-id 0490542b-e741-40b9-be65-45e1e00c9f79 details-level full --format json | $CPDIR/jq/jq -r '(.tasks[0]["task-details"]&lt;STRONG&gt;[0]&lt;/STRONG&gt;.responseMessage)' | base64 -di&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2018 07:57:34 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2839#M217</guid>
      <dc:creator>Marc_Guyard</dc:creator>
      <dc:date>2018-08-01T07:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2840#M218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dameon,&lt;/P&gt;&lt;P&gt;You have missed the index notation for the&amp;nbsp;&lt;SPAN style="color: #333333; background-color: #f6f6f6;"&gt;["task-details"], it should be&amp;nbsp;&lt;STRONG style="background-color: #ffffff; border: 0px; font-weight: bold;"&gt;["task-details"][0]&lt;/STRONG&gt;, as it is a collection.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; background-color: #f6f6f6;"&gt;Robert.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2018 08:17:06 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2840#M218</guid>
      <dc:creator>Robert_Decker</dc:creator>
      <dc:date>2018-08-01T08:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2841#M219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, yes, I did!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gotta love JSON &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.checkpoint.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2018 15:40:19 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2841#M219</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2018-08-01T15:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2842#M220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Gotta love jq&amp;nbsp;being included on the Check Point manager! I did not realize it was in there, I may do more in the shell versus remote through the API because of this!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2018 11:28:56 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/2842#M220</guid>
      <dc:creator>Kellman_Meghu</dc:creator>
      <dc:date>2018-08-02T11:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64232#M3994</link>
      <description>&lt;P&gt;What would be the secret to getting this to work with multiple targets? When I run the command below the output only gives me the output for one firewall no matter how many targets I add.&amp;nbsp;&lt;/P&gt;&lt;P&gt;mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json 2&amp;gt; /dev/null | $CPDIR/jq/jq -r '(.tasks[0]["task-details"][0].responseMessage)' | base64&amp;nbsp;-di&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 22:12:47 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64232#M3994</guid>
      <dc:creator>jpanywhere</dc:creator>
      <dc:date>2019-10-02T22:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64239#M3995</link>
      <description>Right, because run-script creates a separate task for each target and you're only printing the first task details with jq.&lt;BR /&gt;Something like this should work:&lt;BR /&gt;&lt;BR /&gt;mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json 2&amp;gt; /dev/null | $CPDIR/jq/jq -r '(.tasks[]["task-details"][].responseMessage)' | base64 -di</description>
      <pubDate>Wed, 02 Oct 2019 23:49:39 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64239#M3995</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2019-10-02T23:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: run-script output</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64332#M3997</link>
      <description>&lt;P&gt;Thx you were right.&amp;nbsp; However it still didn't work for me. I figured out after you fixed my task issue that base64 didn't like the output from multiple firewalls. I had to add a while loop to get the output from both firewalls.&lt;/P&gt;&lt;P&gt;mgmt_cli -r true run-script script-name "Show State" script "cphaprob state" targets.1 fw1 targets.2 fw2 --format json | $CPDIR/jq/jq -r '(.tasks[]["task-details"][].responseMessage)' | while read line; do base64 -di &amp;lt;&amp;lt;&amp;lt; "$line"; done&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 22:11:28 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/run-script-output/m-p/64332#M3997</guid>
      <dc:creator>jpanywhere</dc:creator>
      <dc:date>2019-10-03T22:11:28Z</dc:date>
    </item>
  </channel>
</rss>

