<?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 Faulty output from bash-scripting on MDS in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147798#M6796</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was making a little BASH-script to export a MDS domain and during that process I needed to get the name of the virtual system, to parse into vsx_provisioning_tool, so I could get all the interfaces out in a text-file.&lt;/P&gt;&lt;P&gt;At first I tried defining the VS_NAME variable as, based on the MDS-Domain name, which I feed manually into the script, along with username and password:&lt;/P&gt;&lt;P&gt;VS_NAME=`mgmt_cli show gateways-and-servers limit 400 -u $MDS_USER -p $MDS_PASS | grep -B4 "$MDS_DOMAIN" | grep -B1 '"CpmiVsClusterNetobj"'| grep 'name: ' | awk -F: '{ print $2 }' | sed 's/"//g' | tr -d ' '`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at the variable with echo, everything seems fine:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@MDS_server:0]# echo $VS_NAME&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;vs-MigrTestSite&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;But the vsx_provisioning_tool command fails:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@30000vmCPMGT04:0]# vsx_provisioning_tool -s $CMA_IP -u $MDS_USER -p $MDS_PASS -o show vd name $VS_NAME&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Version ignis_main, build 996000085&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;not found in database.stSite&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to figure out what went wrong, I simply tried to execute the variable directly:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@MDS_server:0]# $VS_NAME&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;-bash: $'vs-MigrTestSite\r': command not found&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main question:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why is there suddenly both $, ' and \r in the variable?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did a workaround by setting the variable "manually", by feeding the vs-name into the script like I do with the domain-name. Then the variable is just fine.&lt;/P&gt;</description>
    <pubDate>Wed, 04 May 2022 06:55:07 GMT</pubDate>
    <dc:creator>ias_gc-dk</dc:creator>
    <dc:date>2022-05-04T06:55:07Z</dc:date>
    <item>
      <title>Faulty output from bash-scripting on MDS</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147798#M6796</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was making a little BASH-script to export a MDS domain and during that process I needed to get the name of the virtual system, to parse into vsx_provisioning_tool, so I could get all the interfaces out in a text-file.&lt;/P&gt;&lt;P&gt;At first I tried defining the VS_NAME variable as, based on the MDS-Domain name, which I feed manually into the script, along with username and password:&lt;/P&gt;&lt;P&gt;VS_NAME=`mgmt_cli show gateways-and-servers limit 400 -u $MDS_USER -p $MDS_PASS | grep -B4 "$MDS_DOMAIN" | grep -B1 '"CpmiVsClusterNetobj"'| grep 'name: ' | awk -F: '{ print $2 }' | sed 's/"//g' | tr -d ' '`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at the variable with echo, everything seems fine:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@MDS_server:0]# echo $VS_NAME&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;vs-MigrTestSite&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;But the vsx_provisioning_tool command fails:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@30000vmCPMGT04:0]# vsx_provisioning_tool -s $CMA_IP -u $MDS_USER -p $MDS_PASS -o show vd name $VS_NAME&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Version ignis_main, build 996000085&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;not found in database.stSite&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to figure out what went wrong, I simply tried to execute the variable directly:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[Expert@MDS_server:0]# $VS_NAME&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;-bash: $'vs-MigrTestSite\r': command not found&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main question:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why is there suddenly both $, ' and \r in the variable?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did a workaround by setting the variable "manually", by feeding the vs-name into the script like I do with the domain-name. Then the variable is just fine.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 06:55:07 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147798#M6796</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2022-05-04T06:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Faulty output from bash-scripting on MDS</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147800#M6797</link>
      <description>&lt;P&gt;You might have \r at the end - try it&amp;nbsp;&lt;A href="https://www.cyberciti.biz/faq/how-to-remove-carriage-return-in-linux-or-unix/" target="_blank"&gt;https://www.cyberciti.biz/faq/how-to-remove-carriage-return-in-linux-or-unix/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;PRE class="lang-sh s-code-block"&gt;&lt;CODE class="hljs language-bash"&gt;sed &lt;SPAN class="hljs-string"&gt;'s/\\r//g'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lang-sh s-code-block"&gt;&lt;CODE class="hljs language-bash"&gt;tr -d &lt;SPAN class="hljs-string"&gt;'\r'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="mt24"&gt;
&lt;DIV class="d-flex fw-wrap ai-start jc-end gs8 gsy"&gt;&lt;TIME datetime="2013-06-10T13:16:18"&gt;&lt;/TIME&gt;
&lt;DIV class="flex--item mr16"&gt;
&lt;DIV class="js-post-menu pt2" data-post-id="17024833"&gt;
&lt;DIV class="d-flex gs8 s-anchors s-anchors__muted fw-wrap"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="d-flex gs8 s-anchors s-anchors__muted fw-wrap"&gt;
&lt;P&gt;VS_NAME=`mgmt_cli show gateways-and-servers limit 400 -u $MDS_USER -p $MDS_PASS | grep -B4 "$MDS_DOMAIN" | grep -B1 '"CpmiVsClusterNetobj"'| grep 'name: ' | awk -F: '{ print $2 }' | sed 's/"//g' | tr -d ' '&lt;STRONG&gt;|&lt;/STRONG&gt;&lt;CODE class="hljs language-bash"&gt;&lt;STRONG&gt;sed &lt;/STRONG&gt;&lt;SPAN class="hljs-string"&gt;&lt;STRONG&gt;'s/\\r//g'&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/CODE&gt;`&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Best option:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;CODE class="hljs language-bash"&gt;#!/bin/bash -f&lt;BR /&gt;# shellcheck disable=SC2154,SC2086,SC1091,SC2016 &lt;BR /&gt;set +x&lt;BR /&gt;source /etc/rc.d/init.d/functions&lt;BR /&gt;source /etc/profile.d/CP.sh&lt;BR /&gt;source /opt/CPshared/5.0/tmp/.CPprofile.sh&lt;BR /&gt;VS_NAME=$(echo ${mgmt_cli show gateways-and-servers limit 400 -u $MDS_USER -p $MDS_PASS | grep -B4 "$MDS_DOMAIN" | grep -B1 '"CpmiVsClusterNetobj"'| grep 'name: ' | awk -F: '{ print $2 }' | sed 's/"//g' | tr -d ' '} | tr -d '\r')&lt;BR /&gt;vsx_provisioning_tool -s "$CMA_IP" -u "$MDS_USER" -p "$MDS_PASS" -o show vd name "$VS_NAME"&lt;/CODE&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;CODE class="hljs language-bash"&gt;&lt;/CODE&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 May 2022 07:22:51 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147800#M6797</guid>
      <dc:creator>Ofir_Shikolski</dc:creator>
      <dc:date>2022-05-04T07:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Faulty output from bash-scripting on MDS</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147803#M6799</link>
      <description>&lt;P&gt;The&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;PRE&gt;tr -d &lt;SPAN class=""&gt;'\r'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;seems to remove both the $, the ' and the \r from the variable.&lt;/P&gt;&lt;P&gt;I have just never seen this behavior before. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 07:30:35 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Faulty-output-from-bash-scripting-on-MDS/m-p/147803#M6799</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2022-05-04T07:30:35Z</dc:date>
    </item>
  </channel>
</rss>

