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"
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.
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.
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
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)
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.