Linux if then else not working

Hi,

I am writing an Fixlet where first part must be executed if it found Linux 8 else it should go for second part which is RHEL 7.

I worked hard to fix this but it does not execute first part and always went for second part. Then i saw that relevance part is not working. So i had tried a different relevance based on OS to troubleshoot the issue but that relevance gave true on qna but when i run it through the bigfix action script it always went for second part.

Q: if exists file “/etc/redhat-release” whose (exists line whose (exists match (regex “Red Hat Enterprise Linux release 8”) of it) of it) then “true” else "false"
A: true
T: 5248

if exists file “/etc/redhat-release” whose (exists line whose (exists match (regex “Red Hat Enterprise Linux release 8”) of it) of it)

1st part wait mkdir /tmp/gs1
else
2nd part wait mkdir /tmp/gs2

Can you post the snippet of ActionScript that you’re using? I’d want to check the {} are used correctly around relevance substitutions

I’d start with

if {(name of it contains "Red" and major version of it = 7) of operating system}
wait mkdir /tmp/gs1
elseif
 {(name of it contains "Red" and major version of it = 8) of operating system}
wait mkdir /tmp/gs2
endif

On my mobile so this might not fornat correctly

Else-statement doesn’t allow condition, it’s always unconditional. If you want second condition use elseif for it but if you do have elseif-statement, you do need else-statement even if there is nothing in it…

if {(name of it contains "Red" and major version of it = 7) of operating system}
wait mkdir /tmp/gs1
elseif {(name of it contains "Red" and major version of it = 8) of operating system}
wait mkdir /tmp/gs2
else
//do nothing
endif

Oops my bad, that’ll teach me to reply tired :joy:

Are we sure about needing the else after the elseif?

I’m almost certain I’ve created a load of fixlets and never done this that work without issues.

The documentation page (https://developer.bigfix.com/action-script/reference/flow-control/if-elseif-else-endif.html) does not make this at all clear - in fact it almost reads as if the ‘elseif’ is mandatory!

However, the else (whether there is and elseif or not) is optional.

These both work (but have no useful purpose other than prove valid syntax):

if {Monday = day_of_week of current date}
parameter "x"="{"Monday"}"
elseif {Tuesday = day_of_week of current date}
parameter "x"="{"Tuesday"}"
endif


if {Monday = day_of_week of current date}
parameter "y"="{"Monday"}"
elseif {Tuesday = day_of_week of current date}
parameter "y"="{"Tuesday"}"
else
parameter "y"="{"Other"}"
endif
2 Likes

Haven’t tested it in a long time, so maybe not any more but when I did a few years ago wasn’t working without it. May have been a bug at the time…

1 Like

Thanks, Issue has been fixed by using your relevance…Thanks to all for their reply.

1 Like