Relevance in action script

(imported topic written by SystemAdmin)

I’ve been trying to get something to work in action script and I just can’t get there. I am trying to set a parameter in the action script using relevance. I have tried puting curly braces, parentheses, and quotes in all sorts of different places and I’m not getting it. I have also done some searching here and still haven’t figured out where I’m getting it wrong.

So, what I am trying to do is set a parameter based on a key in a text file.

I am trying to have the action script download the text file. For this explanation we’ll call it “test-file.txt”. This file looks like this:

COMPUTER NAME=parameter

COMPUTER NAME2=parameter2

And then I have tried several variations of a parameter line, like so:

parameter “P1” = {key (computer name) of file ((pathname of client folder of current site) & “__Download\test-file.txt”)}

As you can see, what I am trying to do is use the clients computer name to pick which line of the file to use for the parameter.

As I said, I have tried different placement of {}, (), “”, etc… I have even shrunk down the line to:

parameter “P1” = “{key “{computer name}” of file “c:\test-file.txt”}”

Just using a direct pointer to a file for testing purposes. Again, changing around {}, (), “”, etc… It seems that the computer name part is where things are failing. BUT, it seems that I can set a parameter to {computer name} just fine:

parameter “comp” = “{computer name}”

So, I just don’t get what I am missing. If I do “key (computer name) of file “c:\test-file.txt”” in relevance it returns what I am expecting.

The last bit of info I can think of is, when I run the fixlet the result is “”. When I look at the details to see what happened, my parameter line has “Failed” next to it, but no other lines have any status, including the lines above the parameter line. So, to me it looks like BigFix doesn’t like something about the line even before the action script really tries to run.

Hope that all made sense. Thanks for any assistance!

(imported comment written by BenKus)

Looks like you were close… {} go around the whole expresson, but you do want double-quotes if you are setting a parameter… Does this work?

parameter “P1” = “{key (computer name) of file ((pathname of client folder of current site) & “__Download\test-file.txt”)}”

Note that “” usually means there is a syntax error that the agent doesn’t know how to handle…

Ben

(imported comment written by SystemAdmin)

I think I tried this version before, and I just copied and pasted your line just to make sure. It still fails.

(imported comment written by SystemAdmin)

Any more thoughts on this one? Did I possibly discover a bug?

(imported comment written by BenKus)

Hi kirschlk,

Can you please post the file and the whole action?

Ben

(imported comment written by SystemAdmin)

Would it be ok if I e-mail you? There is some stuff in there that I’d rather not post publicly.

(imported comment written by BenKus)

Sure

(imported comment written by drbyars91)

Whatever was the outcome of this one? I’m having the same issue and I’d love to know how to overcome.

In my action script I have

Download now “filename.ini”

Continue if {(size of it = (###) and sha1 of it = (###)) of file “filename.ini” of folder “__Download”}

parameter “ABC” = “{key “{XYZ}}” of section “MySection” of file “filename.ini” of folder (pathname of client folder of current site & “__Download”)}”

This action scripts errors every time on evaluation step at the Parameter line. I found that if I manually place filename.ini in the __Download folder it passes the evaluation step and proceeds. This tells me the evaluation requires the relevance to be valid down to the file/section/key for parameter statements…but the file won’t be there until it is downloaded…

Is there a different way I should word the relevance statement for the evaluation to give the action a go since file does not yet reside in that location?

Note: I am using download now because the ini file is dynamic based on geography, and I need to support a mixture of 6.x and 7.2 clients for ~6 months more, thus I cannot migrate to a prefetch block (yet). Need to find a solution that is backwards compatible.

(imported comment written by jessewk)

Your escaping isn’t quite right. Try this:

parameter “ABC” = “{key “XYZ” of section “MySection” of file “filename.ini” of folder (pathname of client folder of current site & “__Download”)}”

(imported comment written by drbyars91)

The extra escape was necessary because the key values in the downloaded INI file included curly brackets:

MySection

{XYZ}=Value1

{ABC}=Value2

Not ideal given BigFix relevance reliance on the same character, I know.

Regardless, I’ll reiterate that the parameter assignment passes evaluation if the file already exists on the system. To workaround this issue I have created a separate “Pull down configuration file” task and place it in a location like C:\temp. Doing so allows my original task to execute:

parameter “ABC” = "{key “{XYZ}}” of section “MySection” of file “filename.ini” of folder “C:\temp”}

I’d love to avoid the unecessary intermediate task if possible

(imported comment written by jessewk)

Oh, I think I might know what’s going on then. I believe the parameter relevance will get evaluated at the begining of the action before the download actually occurs so the relevance expression will fail if the file isn’t there. Try making your expression plural to avoid evaluation errors:

parameter “ABC” = "{keys “{XYZ}}” of sections “MySection” of files “filename.ini” of folders “C:\temp”}

(imported comment written by drbyars91)

I just came to the same conclusion. Adding a sleep of ~10 seconds between the download now and parameter statements did the trick too. I’ll try the plural as it is cleaner (not intuitive, but cleaner)

Thanks,

Dustin

(imported comment written by drbyars91)

Upon further review neither of these workarounds are successful. I wiped my test box clean to truly confirm and neither the plural folders nor a sleep make a difference. I’m back to a separate task just to get the fine on the target machine before running a task that looks to use the config file ini contents.

there absolutely is a difference in how parameter assignment is evaluated vs. other action commands - I can take the same key extraction statement and place inside a continue if and that line will not be flagged with an error.

(imported comment written by wnolan91)

You have to use ASCii variables to replace the “{” and “}” they are %7b and %7d respectfully.

Q: exists file “f:\filename.ini”

A: True

q: key “%7bXYZ%7d” of section “MySection” of file “f:\filename.ini”

A: Value1

So to add the parameters… you will want to have

parameter “ABC”="{((key “%7bXYZ%7d” of section “MySection” of file “filename.ini” of folders “C:\temp”) as string as lowercase)}"

=======================================================================

For testing purposes, I made the result a “singular string” andchanged the folder location

=======================================================================

parameter “ABC”="{((key “%7bXYZ%7d” of section “MySection” of file “filename.ini” of folders “f:”) as string as lowercase)}"

IF { ((parameter “ABC” ) = “value1” ) }

appendfile TRUE

ELSE

appendfile FALSE

=======================================================================

STATUS: Running action…

Command succeeded parameter “ABC”=“value1”

Command succeeded appendfile TRUE

Command succeeded (file created) appendfile TRUE

Command succeeded appendfile TRUE

DEBUG: Breakpoint reached.