If statement always evaluating to False

(imported topic written by RichB91)

To deal with ongoing struggles of some Windows 2003 SP2 servers not always rebooting when issued either a

Restart 30

from BigFix or even with a

shutdown /r /f /m \servername /t 30

from a command line, I’ve been tasked with verifying that a reboot occurred within the expected window before proceeding.

Here’s a highly simplified sample of the code with which I’ve been experimenting:

Baseline
Task #1
Parameter “DirLogs” = "C:"
Parameter “RebootTimeStamp” = “RebootTimeStamp.txt”
Delete __Appendfile
Appendfile {Now}
Copy __Appendfile {Parameter “DirLogs” & Parameter “RebootTimeStamp”}
Restart 5
Task #2
Parameter “DirLogs” = "C:"
Parameter “RebootTimeStamp” = “RebootTimeStamp.txt”
Parameter “RebootTime” = “{Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)}”
color=blueIf ((Now - Uptime of Operating System) > (Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)) as Time) Then[/color]
Code to proceed…
Else
Code to notify unexpected result…
EndIf

But, regardless of whether I use

or

< in the

If statement, it always evaluates to the Else statement.

It appears to work in QnA but not in the Action test tab or in a live test from the BigFix console.

I suspect I’m just messing up the {} and () symbols in the If statement. Can someone tell me what will work?

Here are the QnA results:

q: Now

A: Mon, 20 Dec 2010 10:09:21 -0500

T: 0.087 ms

q: Uptime of Operating System

A: 2 days, 17:50:19

T: 180.916 ms

Q: Now - Uptime of Operating System

A: Fri, 17 Dec 2010 16:19:03 -0500

T: 179.899 ms

Q: (Line of File “C:\RebootTimeStamp.txt”) as time

A: Fri, 17 Dec 2010 16:48:14 -0500

T: 1.771 ms

Q: ((Now - Uptime of Operating System) > (Line of File “C:\RebootTimeStamp.txt”) as Time)

A: False

T: 182.315 ms

Q: ((Now - Uptime of Operating System) < (Line of File “C:\RebootTimeStamp.txt”) as Time)

A: True

T: 184.806 ms

  • Rich B
1 Like

(imported comment written by NoahSalzman)

Yeah, you need some curly braces in there. The part in bold is Relevance, the rest is Action Script. Relevance must always be put in {} when stuck inside Action Script.

If {

((Now - Uptime of Operating System) > (Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)) as Time)

} Then

Code to proceed…

Else

Code to notify unexpected result…

EndIf

(imported comment written by RichB91)

Thank you. But this hasn’t yet resolved my issue.

I think I tried what you suggested before without success. To be safe, I tried it again.

Using your code in the Action tab of the Relevance Debugger, whether I use

,

<,

= or

!=

, it always evaluates to the Else statement. Regardless of the current time, the time of the acutal reboot, and the uptime of the OS, at

least

one of those options should evaluate to True. Instead, all four evaluate to False.

I’m sure I’m just not dotting an I somewhere but I’m stumped.

-Rich

(imported comment written by NoahSalzman)

Ah, missed it on the first pass: the “then” is silent in Action Script.

http://forum.bigfix.com/viewtopic.php?id=6081

(imported comment written by RichB91)

I knew I was missing (or in reality…adding) something obvious.

That nailed it.

Thanks again!

-Rich

(imported comment written by RichB91)

Again…thank you. Catching the “Then” statement let me make a lot of progress. But I’ve come across another issue in the same code.

When I run each of the 2 tasks individually in the Relevance Debugger Action tab, everything is now working as expected. (Note that within the debugger, I’ve been cancelling the reboot request. I suspect this might be related.) But when I run these two tasks as a single baseline on a test box via the BES console, I get an error.

Specifically, the time just before the reboot is written to the temporary log file. But once the 2nd action kicks off, the code to assign the time from the temporary file to a Parameter generates a

Relevance substitution failed

error.

Run in Relevance Debugger

color=blue

Parameter “RebootTime” = “{Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)}”[/color]

Output to the client-log sub-tab is:

color=green

Command succeeded parameter “RebootTime” = “Mon, 20 Dec 2010 14:24:34 -0500”[/color]

Run from BES Console

color=blue

Parameter “RebootTime” = “{Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)}”[/color]

Output to the client-log file is:

color=red

At 14:34:01 -0500 - actionsite (http://mercury.comanyname.com:52311/cgi-bin/bfgather.exe/actionsite)

Command failed (Relevance substitution failed) parameter “RebootTime” = “{Line of File (Parameter “DirLogs” & Parameter “RebootTimeStamp”)}” (fixlet 146904)

At 14:34:02 -0500 -

ActionLogMessage: (action 146904 ) ending sub action[/color]

I’m wondering if this is related to the reboot just before the 2nd Task and before anyone has logged in interactively.

(imported comment written by RichB91)

Given that it is realy a different issue than the title of this topic, I’m going to repost this as a new topic with additional results from some tests I ran today. Don’t worry about replying to the above topic.