Prefetching
The IBM BigFix Client parses actions before it actually executes them, looking for downloads to prefetch. If the prefetching process does not parse appropriately, an action syntax error is returned and the action is not run. This can be problematic if you are creating actions that work in multiple environments where only one branch of an if statement may parse correctly. For instance, you might want to load files that are unique to specific platforms.
A script like this would seem to work:
if {not exists key "foo" of registry}
prefetch windows_file ...
else if {not exists package "bar" of rpm}
prefetch UNIX_file ...
endif
Here a Windows registry key triggers the first prefetch, while a UNIX package triggers the second. The problem is that the registry Inspector will fail on UNIX systems, and the package Inspector will fail on Windows, causing the prefetch parser to throw an error in both cases.
The answer here is to use cross-platform inspectors (such as name
of operating system
) to make sure the wrong blocks are not
evaluated:
if {name of operating system starts with "Win"}
if {not exists key "foo" of registry}
prefetch windows_file ...
endif
else if {name of operating system starts with "Redhat"}
if {not exists package "bar" of rpm}
prefetch UNIX_file ...
endif
Endif
By checking first for the proper operating system, you can avoid this type of prefetch parse error. However, sometimes there may be no way to avoid a potential error. For instance, an action may create and access a file that doesn't yet exist in the prefetch phase:
wait chkntfs c: > c:\output.txt
if {line 2 of file "c:\output.txt" as lowercase contains "not dirty"}
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="OK"
else
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="FAIL"
endif
In this Windows example, the output file doesn't exist until the script is actually executed. The prefetch parser will notice that the file doesn't exist when it checks for its contents. It will then throw an error and terminate the action. However, you can adjust the if-condition to allow the prefetch pass to succeed. One technique is to use the "not active of action" expression which always returns TRUE during the prefetch pass. You can use this to avoid the problematic block during the pre-parse:
wait chkntfs c: > c:\output.txt
if {not active of action OR (line 2 of file "c:\output.txt" as lowercase
contains "not dirty")}
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="OK"
else
regset "HKLM\Software\MyCompany\" "Last NTFS Check"="FAIL"
endif
By checking first to see whether the action is being pre-parsed or executed, you get a successful prefetch pass and the desired behavior when the action is running.
Syntax
if {<expression>}
<statements>
endif
Example
if {name of operating system = "WinME"}
prefetch patch1.exe sha1:e6dd60e1e2d4d25354b339ea893f6511581276fd size:4389760
http://download.microsoft.com/download/whistler/Install/310994/WIN98MeXP/EN-US
/WinXP_EN_PRO_BF.EXE
wait __Download\patch1.exe
elseif {name of operating system = "WinXP"}
prefetch patch2.exe sha1:92c643875dda80022b3ce3f1ad580f62704b754f size:813160
http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool
/q307869_f323efa52f460ea1e5f4201b011c071ea5b95110.exe
wait __Download\patch2.exe
else
prefetch patch3.exe sha1:c964d4fd345b6e5fd73c2235ec75079b34e9b3d2 size:845416
http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool
/q310507_2f3c5854999b7c58272a661d30743abca15caf5c.exe
wait __Download\patch3.exe
endif
This code snippet prefetches, renames and downloads a file, based on the operating system.
Version 6.0 and above