Lines of file when multiple instances (Aix stanza)

(imported topic written by Solly)

Hello,

I’m trying to pull the value of a line in stanza but having a hard time narrowing it down to just the line I want. The

stanza looks like this:

  • bsh:
  • device = bshdev
  • discipline = fcfs

bsh:

up = TRUE

device = bshdev

discipline = fcfs

GRE-3RDFLOOR-HP8K08:

device = @10

up = TRUE

I need to pull the up = TRUE for the non-commented bsh: stanza, but because the stanzas could be in any order I’m having a hard time working through using “Preceding text of firsts” and isolating the relevancy to just look for the bsh: stanza and ignore all others.

Any help would be very much appreciated.

(imported comment written by BenKus)

I wonder if a regex would work?

Ben

(imported comment written by Solly)

Thanks Ben,

Yeah, I was thinking that too, and far from an expert with regex but have enough examples on the forum I know I could do it if the data was on the same line, but in a stanza like this? Anyone know if that’s possible?

I’ve tried several combinations of concatenation, preceding text and following text, but haven’t been able to isolate the relevance just to the stanza I need (non-commented bsh: stanza).

(imported comment written by SystemAdmin)

Hi Solly,

There are a few Bigfix SCM scripts for AIX that look for this kind of entity. They use a shell script that uses a combination of greps and redirection e.g.

grep -p bsh: /your_file_with_a_stanza | grep -w up > results.file

You could try creating a task that creates/runs the shell script and then use a fixlet/analysis to read at the results from the file.

Mark.

(imported comment written by Solly)

Mark,

Yeah I was thinking of exactly that, but a friend came up with a regex that worked:

(Not for file in my original post but principle is the same and how the stanzas are laid out)

(name of operating system as lowercase contains “2003” and not exists file “c:\test.txt”) AND (if (exists file “C:\rlogin.txt”) then (if ((preceding text of firsts “:” of (following text of first “root:” of (concatenation “|” of lines of file “c:\rlogin.txt”) as string)) contains regex "rlogin

] *=[

*true") then (true) else (false)) else (false))

Obviously tested on a 2003 svr, but for same file as would exist on AIX (/etc/security/user), and testing in AIX works

I really appreciate your time, guys!