<?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 HowTo Error handling in bash in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/HowTo-Error-handling-in-bash/m-p/16540#M1100</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I handle the error messages of an API command while I do pipe the output into a file ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following command will not work for me:&lt;/P&gt;&lt;P style="margin: 0in; font-family: 'Courier New'; font-size: 9.0pt;"&gt;mgmt_cli login user ${USER} password ${PASS} &amp;gt; error_mesaage.txt&lt;/P&gt;&lt;P style="margin: 0in; font-family: 'Courier New'; font-size: 9.0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the following example I do not see the error message. I just see that an error happened but not why:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;mgmt_cli show access-rulebase -s ${login_file} offset 0 limit 40 name "${POLICYNAME}${POLICYTYPE}" | grep -E -B2 "access-rule|access-section" &amp;gt; ${OUTPUT_FILE}&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;if [ $? -eq 1 ]; then&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo "Error listing policy '${POLICYNAME}${POLICYTYPE}'. Aborting!"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;exit 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;fi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I do grep and pipe the result of an API command, I do not see the error message at all. But I need to know what the error message is.&lt;/P&gt;&lt;P&gt;like :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;code: "generic_err_object_not_found"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;message: "Requested object [Policy1 Network] not found"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I get the error code and message in this case ?&lt;/P&gt;&lt;P&gt;How can I print the error code within the IF-statement ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Nov 2018 09:35:30 GMT</pubDate>
    <dc:creator>Sebastian_Gxxx</dc:creator>
    <dc:date>2018-11-14T09:35:30Z</dc:date>
    <item>
      <title>HowTo Error handling in bash</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/HowTo-Error-handling-in-bash/m-p/16540#M1100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I handle the error messages of an API command while I do pipe the output into a file ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following command will not work for me:&lt;/P&gt;&lt;P style="margin: 0in; font-family: 'Courier New'; font-size: 9.0pt;"&gt;mgmt_cli login user ${USER} password ${PASS} &amp;gt; error_mesaage.txt&lt;/P&gt;&lt;P style="margin: 0in; font-family: 'Courier New'; font-size: 9.0pt;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the following example I do not see the error message. I just see that an error happened but not why:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;mgmt_cli show access-rulebase -s ${login_file} offset 0 limit 40 name "${POLICYNAME}${POLICYTYPE}" | grep -E -B2 "access-rule|access-section" &amp;gt; ${OUTPUT_FILE}&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;if [ $? -eq 1 ]; then&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo "Error listing policy '${POLICYNAME}${POLICYTYPE}'. Aborting!"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;exit 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: 9.0pt;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;fi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I do grep and pipe the result of an API command, I do not see the error message at all. But I need to know what the error message is.&lt;/P&gt;&lt;P&gt;like :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;code: "generic_err_object_not_found"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;message: "Requested object [Policy1 Network] not found"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I get the error code and message in this case ?&lt;/P&gt;&lt;P&gt;How can I print the error code within the IF-statement ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2018 09:35:30 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/HowTo-Error-handling-in-bash/m-p/16540#M1100</guid>
      <dc:creator>Sebastian_Gxxx</dc:creator>
      <dc:date>2018-11-14T09:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: HowTo Error handling in bash</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/HowTo-Error-handling-in-bash/m-p/16541#M1101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just redirect stderr to stdout.&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;&lt;SPAN class=""&gt;command &lt;/SPAN&gt;&lt;SPAN class=""&gt;2&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:28:21 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/HowTo-Error-handling-in-bash/m-p/16541#M1101</guid>
      <dc:creator>Danny</dc:creator>
      <dc:date>2018-11-14T11:28:21Z</dc:date>
    </item>
  </channel>
</rss>

