Iterating txt file,

I have this txt file which has servername and other detail in the file. I want iterate through the files one line at time and take action based on 3rd column.

/var/mft/bigfix_mqft/ADD_SVR_To_Bigfix_MQFT_Grp.txt
server1,TC_Application=MQFT,A
server2,TC_Application=MQFT,A
e.g
for loop (lines of file “/var/mft/bigfix_mqft/ADD_SVR_To_Bigfix_MQFT_Grp.txt”) whose (it does not contain regex “^#” )
servername=??
mqft_app=??
action=??
if action = "A"
set besclient setting (mqft_app) for that servername
if action = "D"
remove besclient setting (mqft_app) for that servername.

I am struggling a bit to follow your requirement - is this file going to be placed on central location OR is it going to be on each client? If it is the former than you can write the entire logic to be done via an outside script (bash, powershell, etc) and as last step once you’ve taken care of all the logic/parsing/etc do RestAPI call to BigFix against each of the servers to change the settings accordingly. IF you are aiming to do this on EACH endpoint, I’d question your design of the workflow cause this is extremely redundant - imagine you have the same exact file on let’s say 100 machines and each client does exact same parsing through the exact same file to do the same exact function…

That said, if you insist on doing it this way - there isn’t a for loop in actionscript but what you can do is use appendfile to generate a dynamic script. The only problem is that you can’t really use that with any native actionscript commands - so you won’t be able to setting “mqft_app”="???" on “{now}” for client. There is a work around on Unix though - you can manually echo stuff to the BigFix config file and just restart the client to “load” them up (on Windows is easier cause no restart required, just update registry keys).

Also, if you can play around with the format of the text file make the delimiter ", " if you do you can directly index each parameter within the line without any kind of parsing. Same goes for the name of the parameter - if you have close control of the file, you don’t really need to pass the name of the parameter and just leave the value. Anyway, adjusted the example below to parse it a bit as is.

q: (if (item 1 of it = “A”) then (“echo %22\n%22>>/var/opt/BESClient/besclient.config;echo %22[Software\BigFix\EnterpriseClient\Settings\Client\mqft_app]%22>>/var/opt/BESClient/besclient.config; echo %22value = " & item 0 of it & “%22>>/var/opt/BESClient/besclient.config”) else (”…need to write some commands to take out the same 3 lines that you create out of a file - would imagine you can use sed to do it…")) of ((if (it contains “=”) then (following text of first “=” of it) else (it)) of tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by “,” of it) of (“server1,TC_Application=MQFT,A”; “server2,TC_Application=MQFT,B”)
A: echo “\n”>>/var/opt/BESClient/besclient.config;echo “[Software\BigFix\EnterpriseClient\Settings\Client\mqft_app]”>>/var/opt/BESClient/besclient.config; echo “value = MQFT”>>/var/opt/BESClient/besclient.config
A: …need to write some commands to take out the same 3 lines that you create out of a file - would imagine you can use sed to do it…
T: 0.319 ms
I: plural string

And putting it all together:

delete __appendfile
delete “/tmp/test.sh”

appendfile {concatenation “%0a” of ((if (item 1 of it = “A”) then (“echo %22\n%22>>/var/opt/BESClient/besclient.config;echo %22[Software\BigFix\EnterpriseClient\Settings\Client\mqft_app]%22>>/var/opt/BESClient/besclient.config; echo %22value = " & item 0 of it & “%22>>/var/opt/BESClient/besclient.config”) else (”…need to write some commands to take out the same 3 lines that you create out of a file - would imagine you can use sed to do it…")) of ((if (it contains “=”) then (following text of first “=” of it) else (it)) of tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by “,” of it) of lines of file “/var/mft/bigfix_mqft/ADD_SVR_To_Bigfix_MQFT_Grp.txt”)}
move __appendfile “/tmp/test.sh”

“%0d%0a” is carriage return for Windows files, if I remember Unix/Linux it was just “%0a”. Hope this helps you.

This file will stay in admin server. It will not be populated any other hosts
adminserver:/var/mft/bigfix_mqft/ADD_SVR_To_Bigfix_MQFT_Grp.txt

We want bf policy to read that file when it has changed. then parse the comma and set the beslclient porperty for listed host in the txt file. I will just keep 1 server which needs to update the besclient property.

$adminserver:/var/mft/bigfix_mqft/ADD_SVR_To_Bigfix_MQFT_Grp.txt
nameofsrvrabc,TC_Application=MQFT,A

get the servername
get 3 column will be A or D
if 3rd col is "A"
check besclient property of “nameofsrvrabc” has “TC_Application=MQFT”, if not then set it
if 3rd col is "D"
if besclient property of “nameofsrvrabc” has “TC_Application=MQFT”, then delete it.

You are best writing it in other scripting languages and then creating a fixlet just to call the script. I have similar structured functionality where on our root server would parse out our CMDB file into individual .json files for each endpoint and IF any machine’s JSON file has changed I post a RestAPI call to set “CMDBUpdateRequired” client setting which forces another “distribute CMDB data file” to run. You are just not going to get it working cause you cannot set client setting from an admin server to another server without some kind of external/remote call and it won’t be done in actionscript.

1 Like

I like parsing problems like this.

q: lines of file "group.txt" of folder "c:\test"
A: server1,TC_Application=MQFT,A
A: server2,TC_Application=MQFT,A
A: server3,TC_Application=MQFT,D
A: server4,TC_Application=BOB,A

Add in spaces after the commas to allow for Tuple String treatment in relevance
q: (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test"
A: server1, TC_Application=MQFT, A
A: server2, TC_Application=MQFT, A
A: server3, TC_Application=MQFT, D
A: server4, TC_Application=BOB, A

now we can get our "Columns" into BigFix strings and use them to feed a .bat file
q: (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test"
A: server1, TC_Application=MQFT, A
A: server2, TC_Application=MQFT, A
A: server3, TC_Application=MQFT, D
A: server4, TC_Application=BOB, A

now "do things to each one" based on the criteria
q: ("COMMAND " & item 0 of it & " THING " & following text of last "=" of item 1 of it & "" & (if (item 2 of it = "A") then (" ADD") else (" DELETE") ) ) of (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test" 
A: COMMAND server1 THING MQFT ADD
A: COMMAND server2 THING MQFT ADD
A: COMMAND server3 THING MQFT DELETE
A: COMMAND server4 THING BOB ADD

Now add in carriage returns to be added into a .BAT file
q: concatenation "%0d%0a"  of ("COMMAND " & item 0 of it & " THING " & following text of last "=" of item 1 of it & "" & (if (item 2 of it = "A") then (" ADD") else (" DELETE") ) ) of (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test" 
A: COMMAND server1 THING MQFT ADD%0d%0aCOMMAND server2 THING MQFT ADD%0d%0aCOMMAND server3 THING MQFT DELETE%0d%0aCOMMAND server4 THING BOB ADD
3 Likes

$adminserver:/home/abc/list2.txt
newserver1,A

Not sure if this doable… I would like to set this as policy to read “adminserver:/home/abc/list2.txt”, and update “newserver1” client setting.

 ( (if (item 1 of it = "A") then (
if { exists setting "TC_Application" whose( value of it contains "MQFT") of client whose name = (item 0 of it)}
        setting "TC_Application"="MQFT" on "{parameter "action issue date" of action}" for client whose name = (item 0 of it)
    endif
 move /home/abc/list2.txt /home/abc/list2.txt.date

) else "NA" )) of (tuple string item 0 of it, tuple string item 1 of it) of (concatenation ", " of substrings separated by "," of it) of lines of file "list2.txt" of folder "/home/abc/"

Oh - you want to find “this computer” in the text file and set a local setting based on that one line. Gotcha

q: lines of file "group.txt" of folder "c:\test" 
A: server1,TC_Application=MQFT,A
A: server2,TC_Application=MQFT,A
A: Brolly33,TC_Application=BROLLY,D
A: server4,TC_Application=BOB,A
T: 3.475 ms
I: plural file line

q: (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test"
A: server1, TC_Application=MQFT, A
A: server2, TC_Application=MQFT, A
A: Brolly33, TC_Application=BigFix, D
A: server4, TC_Application=BOB, A
T: 2.915 ms
I: plural ( string, string, string )

q: computer name
A: Brolly33
T: 2.131 ms
I: singular string

q: (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) whose (item 0 of it as lowercase = computer name as lowercase) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test"
A: Brolly33, TC_Application=BigFix, D
T: 1.927 ms
I: plural ( string, string, string )

q: (following text of last "=" of item 1 of (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) whose (item 0 of it as lowercase = computer name as lowercase) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test") | "MISSING"
A: BigFix
T: 0.905 ms
I: singular string

And your possible action script to set the local computer setting based on what is in the file:

setting "TC_Application"="{(following text of last "=" of item 1 of (tuple string item 0 of it, tuple string item 1 of it, tuple string item 2 of it) whose (item 0 of it as lowercase = computer name as lowercase) of (concatenation ", " of substrings separated by "," of it) of lines of file "group.txt" of folder "c:\test") | "MISSING"}" on "{parameter "action issue date" of action}" for client

1 Like

I think you misunderstood.
bigfix policy will read the text file from “adminserver:/home/abc/list2.txt”. Policy will only run if file exist in “adminserver” server. Txt will have only 1 server in it.
If txt file exist the read the file and set the setting on “target new server” which is listed in the text file. – That’s i am not if its doable.

Let say - policy is read this file from adminserver and sets the client setting of “target” “newserver1” not “this computer”.
$adminserver:/home/abc/list2.txt
newserver1,A

I agree that I don’t understand your requirement.

BigFix actions run on BigFix agents and interact with the local server where the BigFix agent is running.

It is starting to sound like you want BigFix agent on Server A to make some changes on Server B and Server C and Server D?

yah. Policy will only check adminserver for txt file. If txt file has new “target” server then change setting on “target” server.
we have fixlet available which does that “tc_application”. Can we spawn the that fixlet from the policy action script? I wonder its not.

I don’t think you can do this in pure Action Script, because local agent has no permissions on remote servers.

Sounds like you need to build an external script to read your file and generate REST API calls into BigFix server in order to generate one action per endpoint in your file, and each individual action would have the field from your input file. It’s more like an integration than a Fixlet.

yah. I though of using rest api to read txt file and change the setting of the “target” server.