Relevence quote within quotes failing

(imported topic written by olsonc5891)

I have a fairly simple relevence query but not sure how to handle it. The line I am looking for in a file has quotes and an operator in it so it’s not giving me the results I need. How do you manage quotes within quotes? Here is the relevence query:

Exists line containing “” of file “C:\Program Files\folder1\folder2\Site\Log4Net.config”

It sees “ALL” as an operator and wants it defined. How do I get around this?

Below is some of the actual text from the file:

Thanks,

Chris

(imported comment written by NoahSalzman)

Use %22 for the quote characters:

Exists line containing “” of file “C:\Program Files\folder1\folder2\Site\Log4Net.config”

(imported comment written by olsonc5891)

Thanks Noah. I am working through the Training Guide for Writing BES Custom Content so hopefully, I will be able to find my own answers in time.

Chris

(imported comment written by jessewk)

It looks like you are parsing an XML document. If it’s properly formed, the xpath inspectors should make it easy and quick to find the info you’re looking for.

(imported comment written by olsonc5891)

Thanks Jess.

It is an XML doc. I am new at this so haven’t attempted to use xpath inspectors. Where would be a good place for me to start (reading/training)?

As it turns out, I am gettting requests to edit a few of these files. Currently, my processes is to create a software deployment task to fix these issues. First, I find the file and edit it based on the requirement. Then, I use the software distribution wizard to deploy the edited file if the machine meets the relevence. However, in many cases, there is something eles in the file that is different based on the build so rather than deploying just the edit, I have to create many different groups and a separate file for each build. If I could edit a line in the file and not have to replace the entire file itself, it would make my life a LOT easier. Is there a way to push a line edit in an xml file rather than trying to replace the entire file?

Thank you in advance for you expertise and advise.

Chris

(imported comment written by NoahSalzman)

If the “string to be replaced” is fairly unique you can use this approach:

http://forum.bigfix.com/viewtopic.php?pid=5913#p5913

If the text you are looking for is not particularly unique, or is a block of text that spans multiple lines, then the “find text and replace it” logic in your script will have to be a bit more sophisticated than that example.

(imported comment written by olsonc5891)

One is to add a parameter to an xml file. It is simply appended to a section of the file.

The string is:

I need to add:

waitChangeNotification=“315360000” maxWaitChangeNotification=“315360000”

So it looks like this:

Here is my first attempt. Unfortunately, I do understand the second part of the logic so this is a crapshoot based on previous code:

// store the file location

parameter “filename” = “c:\web.con”

// iterate through the file replacing lines as necessary

appendfile {concatenation “%0d%0a” of ( if (it starts with “<httpRuntime”) then (preceding text of first "enableKernaelOutputCache=“false” of it) waitChangeNotification=“315360000” maxWaitChangeNotification=“315360000” of lines of file(parameter “filename”)}

(imported comment written by NoahSalzman)

Try this… I haven’t tested it myself, so I don’t know if the %22 instead of quotes will work or not. Also, I assume that your file only has one line that starts with “<httpRuntime”.

// store the file location parameter 
"filename" = 
"C:\web.com"   
// iterate through the file replacing lines as necessary appendfile 
{concatenation 
"%0d%0a" of ( 

if (it starts with 
"<httpRuntime") then (preceding text of first 
"<httpRuntime" of it) & 
"<httpRuntime executionTimeout=%221200%22 maxRequestLength=%2210240%22 enableKernelOutputCache=%22false%22 waitChangeNotification=%22315360000%22 maxWaitChangeNotification=%22315360000%22/>" 

else it ) of lines of file (parameter 
"filename")
}     
// backup the old file (first delete any old backup files) delete 
"{parameter "filename
"}.bak" move 
"{parameter "filename
"}" 
"{parameter "filename
"}.bak"     
// replace with the new file move __appendfile 
"{parameter "filename
"}"

(imported comment written by jessewk)

Hi Chris,

You can find xpath documentation in the inspector guide.

For simple text edits, the approach Noah points to will work well. For more complicated edits, you will want to write a script in your favorite language, hopefully something that has good XML editing support, for example anything that supports E4X.

For your example, I think you can use the simple method. You look like you’re close. I haven’t tested this, but give it a try:

// store the file location
parameter “filename” = “c:\web.con”
// iterate through the file replacing lines as necessary
appendfile {concatenation “%0d%0a” of ( if (it starts with “<httpRuntime”) then ("") else it) of lines of file(parameter “filename”)}

(imported comment written by jessewk)

haha… looks like Noah beat me to it.

(imported comment written by olsonc5891)

We are very close. All the steps completed, but when I viewed the file, I could not see that the edit took place. The file did not chang. I searched the file for “waitChangeNotification” after the process ran and it isn’t there. I tried both yours and Noah’s code but the result is the same. What can we be missing?

CO

(imported comment written by NoahSalzman)

My guess is that there is white space before “<httpRuntime”. Try it again with

(it contains “<httpRuntime”)

instead of

(it starts with “<httpRuntime”)

(imported comment written by olsonc5891)

Good call! IT WORKED! Thank you both VERY much! :slight_smile: