Simple relevance to verify specific text on a line

Ok thanks I see a couple of possible problem points.

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

Here you should probably invoke /bin/sh directly. The ‘__appendfile’ you created doesn’t have the #!/bin/sh at the start of it, nor the ‘.sh’ filename extension, so it won’t be recognized as a shell script. Try

wait /bin/sh -c "{(client folder of current site as string) & "/__appendfile"}"

There are also a few things around your ‘if’ statement…

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

…this line lacks the closing } symbol at the end of the line. It also comes inside your createfile block, so the whole ‘if’ statement is literally inside the script you’re creating - not doing the flow control that you want. Move this whole line to before the ‘delete /tmp/Updater.sh’ statement and move the ‘endif’ for it to after executing the updater.sh script (and, oh yeah, execute the updater.sh with its own wait statement). The logic should be 'IF {an update is needed} (create & run & delete updater script) ENDIF

The If line closing tag I noticed just after I posted this, dumb clerical error there the rest I didn’t realize how that was supposed to look and flow in Bigfix so that definitely provides some clarity for me. I think I have implemented your suggestions below, let me know if it still looks like I am off or missing something in your explanation. Once again I appreciate all the help Jason.

//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 /bin/sh -c "{(client folder of current site as string) & "/__appendfile"}"

delete __appendfile
delete /tmp/Query.sh


if {exists file "/tmp/StopSaleQuery.txt" whose (line 2 of it = regex("172329[[:space:]]+FE[[:space:]]+CHPTL[[:space:]]+CDR[[:space:]]+CHPPD[[:space:]]+KIT[[:space:]]+0"))}
delete /tmp/Updater.sh
createfile until EOF
#!/bin/sh
	MariaDB Login "Maria DB Update query"
	MariaDB Login "Maria DB Update query"
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 /bin/sh -c "{(client folder of current site as string) & "/__appendfile"}"
endif

delete appendfile
delete /tmp/Updater.sh

Ill add that I no longer get failures but I do get an exit code 126.

Perhaps a space is needed on

appendfile cd /tmp

I’d also be careful about executing scripts in /tmp. It may not apply in your case, but I’ve come across systems that mount /tmp with noexec, so nothing can execute from /tmp. But that’s probably a “later” issue.

I completely understand that. We have been asked to run any scripts like this in /tmp and make sure the scripts are removed without a trace when were done for security purposes so I think I am good there but it’s good food for thought moving forward.

1 Like

Finally got past the 126 error thank you. Another question, if I want to add a computer name check in addition to the regex line could I just do the following?:

AND (computer name) as lowercase contains “34” or (computer name) as lowercase contains “58”

You’d need to group the two computer terms together like and ( (computer name) as lowercase contains "34" or (computer name) as lowercase contains "58" )

It’s more efficient to check the computernames than to run the regex, though, so put the computer name checks first and the regex check last instead. Even better if you limit which machines can run the task at all,putting the computer check in the Task Relevance instead.

So from an efficiency standpoint is it more efficient within bigfix to have this one big job that handles multiple scenarios across a large set of computers or would it be more efficient to break that up into what my original plan was and have one fixlet that creates the file and several smaller tasks to run when it finds incorrect values in the file?

I’m not sure I follow…I think it depends a lot on whether you want the same thing to happen across the computers or if you want something different to happen on these two hosts because they are special in some way.

What needs to happen will be unique to each computer in some cases and the same in others. I think I may split things apart now that I think about it more. Thank you so much for all of your assistance today Jason I appreciate it.

1 Like