Simple relevance to verify specific text on a line

So currently I am running a fixlet that creates a file with output from several computers and then I want to have a task that looks at the output of the file and runs if it can confirm certain information. In this case the primary thing I am wanting to confirm is that last 0 on the end BUT I also want to confirm the 1732 FE CHPT is there to triple check I am on the right line and not running the task at an inappropriate time. I have confirmed as pasted in here is the output to the file but this keeps kicking back not relevant when I run the task. I think I may be missing something basic with my relevance. Any help that can be provided is appreciated.

line 2 of files "tmp/query.txt" containing "1732 FE CHPT 0"

On a phone so can’t check the syntax but something like

exists file "tmp/query.txt" whose (line 2 of it contains "1732 FE CHPT 0")

2 Likes

And because BigFix is soooo cool, here’s another way to do it :smiley:

exists (line 2 of it) whose (it contains "1732 FE CHPT 0") of file "tmp/query.txt"

Thank you for the quick response. so I am still getting not relevant back is there a way to account for possible extra spaces or something silly like that? I have been directly copying the line from the file but there’s got to be something silly i’m missing or a dumb spacing/casing type of situation going on.

Are you able to run qna on a Server with the File?
You can get rid of the Spaces using trim
https://github.com/bigfix/developer.bigfix.com/blob/master/site/pages/relevance/_reference/docs/string.md#string-as-trimmed-string–string
I can Look for an Example tomorrow

…is it the lack of fowardslash at the start of “/tmp/” ?

It isn’t but that’s a good catch i’ve since corrected. I can get it to work when I just call one piece of the line but not anything separated by spaces so trimming may be what I need.

I’ll bet at least one of those spaces isn’t a space…maybe it’s two spaces, or a tab, or something like that.

If you can figure out the exact spacing / tab characters you could search for that string instead (using the percent-encoded %09 in place of ‘Tab’ if necessary).

Or, you can compare it with a Regular Expression, allowing at least one (and as many as necessary) spaces/tabs between the characters. Should be something like

exists file "/tmp/query.txt" whose (line 2 of it = regex("1732[[:space:]]+FE[[:space:]]+CHPT[[:space:]]+0"))

I may have to do a regex the output is coming in from a mariadb query and then outputting to a txt file and then im reading from that. When I copy from the txt file or from a simple analysis I made I get a note relevant flag so there’s got to be some tab or something that I am unaware of that’s causing the issue. Let me try the regex and see how that goes.

The regex ended up working thank you Jason and all who contributed. It’s refreshing how nice and welcoming folks are on these forums. I did have a follow up question though it’s technicality may be over my head ill ask it anyways… Right now I am having to run 2 fixlets together. One to login to a database of a computer run a query with a shell script and output that to a file and then use another fixlet to verify its contents and act upon based upon those contents. Is it possible to do all of that in one job where the bigfix action script could run the database query and then act based upon the output it finds?

Sure! You’d just put an if {relevance} block in your Action Script.

Basically your ActionScript would then be something like

// Do the things that generate the /tmp/query.txt file output

if {exists file "/tmp/query.txt" whose (line 2 of it = regex("1732[[:space:]]+FE[[:space:]]+CHPT[[:space:]]+0"))}
  // do the things you want to happen when the query returns this result
endif

This is a brilliant forum. In my early days (read months) I learned so much reading current posts and using the search function to home in to pertinent posts.

Bigfix.me is also a great source of content to help get your syntax correct

3 Likes

So I tried this and I got a bit of strange behavior. It came back as Failed Exit code 126 but when I looked on the computer I tested it on the job ran and did what I anticipated it should. Which per google means command invoked could not execute…well that’s a lie it executed. Any idea what I did wrong here?

As someone who was sort of thrown into the deep end of bigfix and trying to tread water as best I can it’s been refreshing to actually get assistance and find kind like minded folks. Unfortunately rather rare on the internet.

Hmm may need to see a snippet from the client log, or at least the ActionScript line that returns that error code.

In an action the ‘exit code of action’ is the errorlevel returned by the most recent ‘wait’ command, so if you have more than one command line you can only determine the return code of the most recent one.

And, yes, ‘126’ is that the command could not be executed, and it’s usually because of an incorrect PATH or fully-qualified path to the command line is not correct. Also if you are depending on some environment variables, those usually aren’t processed by the non-login, root shell that we launch (i.e. “.profile” or “.bashrc” or something may not have been sources by the shell)

It seems to not like the if statement as this is where it fails every time with the exit code 126

if {exists file "/tmp/Query.txt" whose (line 2 of it = regex("172329[[:space:]]+FE[[:space:]]+CHPTL[[:space:]]+0"))}

Have you fixed the “smart quotes” on the line? It’s hard to tell from a paste in to the Forum.
The action may fail on that line, but that line is not providing the return code value - the exit code would only comes form spawning an external process, with the ‘wait’ command. The ‘126’ would have come from earlier in the script.

I fixed my code so it was in a code block sorry about that. I don’t think theres an issue with the quotes but i’ve honestly never heard of smart quotes before. Here is my full setup as of right now with sensitive info replaced with text blurbs. Trying to do both the creation of the file and the if/endif all in one here.

//Shell to Action Script Conversion Utility
delete __appendfile
delete /tmp/Query.sh
delete /tmp/Query.txt

createfile until EOF
#!/bin/bash

query="
MariaDB Query I can't share but assume it lives here.;
"

(Login info for maria db  database"$query" ; Login info for second mariadb database "$query") > /tmp/Query.txt
~


EOF

copy __createfile /tmp/Query.sh

//Shell to Action Script Conversion Utility
delete __appendfile

appendfile cd /tmp
appendfile chmod +x Query.sh
appendfile ./Query.sh

//modify appendfile to allow execution
wait /bin/sh -c "chmod 555 {(client folder of current site as string) & "/__appendfile"}"

//execute shell script as written
wait "{(client folder of current site as string) & "/__appendfile"}"

delete __appendfile
delete /tmp/Query.sh



delete /tmp/Updater.sh
createfile until EOF
#!/bin/sh
if {exists file "/tmp/Query.txt" whose (line 2 of it (line 2 of it = regex("172329[[:space:]]+FE[[:space:]]+CHPTL[[:space:]]+0")))
	MariaDB Login "Maria DB Update query"
	MariaDB Login "Maria DB Update query"
endif
EOF

copy __createfile /tmp/Updater.sh

delete__appendfile

appendfile cd/tmp
appendfile chmod +x Updater.sh
appendfile ./Updater.sh

//modify appendfile to allow execution
wait /bin/sh -c "chmod 555 {(client folder of current site as string) & "/__appendfile"}"

//execute shell script as written
wait "{(client folder of current site as string) & "/__appendfile"}"

delete appendfile
delete /tmp/Updater.sh

Though ive found in my testing I can completely remove the second if/endif block and im still getting the error code 126 so there’s something wrong with the top block that’s creating the file.