Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
ias_gc-dk
Contributor
Jump to solution

Faulty output from bash-scripting on MDS

Hi

 

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.

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:

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 ' '`

 

Looking at the variable with echo, everything seems fine:

[Expert@MDS_server:0]# echo $VS_NAME
vs-MigrTestSite

But the vsx_provisioning_tool command fails:

[Expert@30000vmCPMGT04:0]# vsx_provisioning_tool -s $CMA_IP -u $MDS_USER -p $MDS_PASS -o show vd name $VS_NAME
Version ignis_main, build 996000085
not found in database.stSite

 

Trying to figure out what went wrong, I simply tried to execute the variable directly:

[Expert@MDS_server:0]# $VS_NAME

-bash: $'vs-MigrTestSite\r': command not found

 

Main question:

Why is there suddenly both $, ' and \r in the variable?

 

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.

0 Kudos
1 Solution

Accepted Solutions
Ofir_Shikolski
Employee
Employee

You might have \r at the end - try it https://www.cyberciti.biz/faq/how-to-remove-carriage-return-in-linux-or-unix/

or:

sed 's/\\r//g'

or 

tr -d '\r'

 

 

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 ' '|sed 's/\\r//g'`

 

Best option:

#!/bin/bash -f
# shellcheck disable=SC2154,SC2086,SC1091,SC2016
set +x
source /etc/rc.d/init.d/functions
source /etc/profile.d/CP.sh
source /opt/CPshared/5.0/tmp/.CPprofile.sh
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')
vsx_provisioning_tool -s "$CMA_IP" -u "$MDS_USER" -p "$MDS_PASS" -o show vd name "$VS_NAME"

View solution in original post

2 Replies
Ofir_Shikolski
Employee
Employee

You might have \r at the end - try it https://www.cyberciti.biz/faq/how-to-remove-carriage-return-in-linux-or-unix/

or:

sed 's/\\r//g'

or 

tr -d '\r'

 

 

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 ' '|sed 's/\\r//g'`

 

Best option:

#!/bin/bash -f
# shellcheck disable=SC2154,SC2086,SC1091,SC2016
set +x
source /etc/rc.d/init.d/functions
source /etc/profile.d/CP.sh
source /opt/CPshared/5.0/tmp/.CPprofile.sh
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')
vsx_provisioning_tool -s "$CMA_IP" -u "$MDS_USER" -p "$MDS_PASS" -o show vd name "$VS_NAME"

ias_gc-dk
Contributor

The


tr -d '\r'


seems to remove both the $, the ' and the \r from the variable.

I have just never seen this behavior before. Thanks.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events