- CheckMates
- :
- Products
- :
- Developers
- :
- API / CLI Discussion
- :
- Re: Faulty output from bash-scripting on MDS
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Are you a member of CheckMates?
×- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Tags:
- cli
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 +xsource /etc/rc.d/init.d/functionssource /etc/profile.d/CP.shsource /opt/CPshared/5.0/tmp/.CPprofile.shVS_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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 +xsource /etc/rc.d/init.d/functionssource /etc/profile.d/CP.shsource /opt/CPshared/5.0/tmp/.CPprofile.shVS_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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
