LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-12-2012, 02:15 PM   #1
nagileon
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
script failing - colorization getting in way


How do I get rid of the colorization info from a variable:

rvc user@server --cmd "vm.on /server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/$thevm" --cmd "exit"

no matches for "/server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/XYZ.pool.local-PoolX\e[0m"

I should get: XYZ.pool.local-PoolX

But the clorization infor is attached to the variable for some strange reason.
 
Old 09-12-2012, 03:46 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
The answer to your question may depend on details which you don't appear to have provided.

If however you are doing your script, will always cause the same sequence of characters to be placed at the end of the value you expect in thevm variable, so that you will always need to remove the same sequence of characters \e[0m from the end of the value, then it's fairly simple. If instead, there can be a different sequence of characters, that would be a somewhat different solution.

However, rather than removing the sequence of escape characters from the end of the variable value, the more correct solution would be to fix the problem that's causing them to be there. But without the details of how you are doing your script, we can't necessarily help with that.

When I put this code in a file:

Code:
back_slash_position=`expr index "/server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/XYZ.pool.local-PoolX\e[0m" '\'`
((back_slash_position -= 1))
corrected_path=`expr substr "/server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/XYZ.pool.local-PoolX\e[0m" 1 $back_slash_position`
echo $corrected_path
make the file executable, then execute it, I get this output:

Code:
/server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/XYZ.pool.local-PoolX
which is what I'm guessing is the value you're expecting to supply to the rvc command.

HTH.
 
Old 09-13-2012, 07:38 AM   #3
nagileon
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
#!/bin/bash

for n in {1..1000}
do

for themachine in `rvc user:"password"@vsphereserver --path /vsphereserver/Development/computers/TheCluster/resourcePool/pools/PoolX/vms --cmd "exit"|awk '{print $2 $3}'`
do
a=`echo $themachine|grep poweredOn`
x=`echo $a|wc -m`
echo $x
done

if [ $x -gt 1 ]; then
echo "Not all of the machines are off at the moment! Waiting!"
else

for thevm in `rvc user:"password"@vsphereserver --path /vsphereserver/Development/computers/TheCluster/resourcePool/pools/PoolX/vms --cmd "exit"|awk '{print $2}'|tr -d ":"`
do
echo "Powering on: "$thevm

rvc user:"password"@vsphereserver --cmd "vm.on /vsphereserver/Development/computers/TheCluster/resourcePool/pools/PoolX/vms/$thevm" --cmd "exit"
done
break
fi

sleep 1

done

The funny part is that the "echo "Powering on: "$thevm" part gives me the correct VM name. But then the malformed name is injected into the rvc command.
Warmest regards,
Peter
 
Old 09-13-2012, 05:49 PM   #4
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Quote:
Originally Posted by nagileon View Post

[...]

The funny part is that the "echo "Powering on: "$thevm" part gives me the correct VM name. But then the malformed name is injected into the rvc command.

[...]
AFAIK, as soon as I saw the \e[0m escape/control sequence, I recognized it. It's a sequence that turns off special modes for some terminals. If rvc normally expects that it's dealing with a terminal and using colorization to make distinctions between one thing and another, then at the end of its output, it would likely try to discontinue the various modes used to do the colorization.

If the control sequence is being placed in the variable, and the type of terminal ( or terminal emulation ) you are using, can understand that control sequence, then when you just echo the value, it would be interpreted by the "terminal". I strongly suspect that's why you don't see the characters when you just echo them to the "terminal".

To see if the sequence is being placed into the variable, instead of just echoing the value to the "terminal", try this command sequence:

Code:
echo "Powering on: "$thevm  |  od -bc
to let the so called "Octal Dump" command, show you byte by byte, what characters are stored in your thevm variable.

I would look at the documentation for rvc to see if there is some mode, which prevents rvc from doing the colorization.

If that one control sequence is the only one you ever get in your thevm variable, and you get it consistently, you can just chop it out, as we've already discussed. In fact, since you are already using awk within your bash script, you could just add to the awk code to either chop off the end of the string, if you always have that single escape sequence there, or if you get different control sequences, awk could use regular expressions to match the various potential control sequences, and remove them, before printing the selected fields from the rvc command output.

Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mirror slackware current script failing vdemuth Slackware 13 07-26-2012 10:54 AM
[SOLVED] script with 'tr' failing greenpool Linux - Newbie 11 08-14-2011 02:31 AM
[SOLVED] lighttpd startup script failing tkmsr Programming 3 08-07-2010 03:02 PM
Authentication failing in Perl DBI script resetreset Programming 4 11-19-2008 09:01 AM
mkbootdisk script is failing emalossi Fedora 3 01-14-2006 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration