Prefetch with variables

any idea why that won’t work?
complains “unable to parse action script…” Line 10 is the prefetched line.

parameter "_file_name"="file.tar.gz"
parameter "_file_sha1"="03a43362aab9a33473a10e1311edaf1b2861df30"
parameter "_file_bytes"="20156340737"

parameter "_file_URL"="http://server.domain.com/dir"

prefetch {parameter "_file_name" of action} sha1:{parameter "_file_sha1" of action} size:{parameter "_file_bytes" of action} {parameter "_file_URL" of action}/{parameter "_file_name" of action}

Seems silly the normal “prefetch” doesn’t work, but a coworker pointed out I should use a prefetch block and that did the trick.

begin prefetch block
	parameter "_file_name"="file.tar.gz"
	parameter "_file_sha1"="03a43362aab9a33473a10e1311edaf1b2861df30"
	parameter "_file_bytes"="20156340737"
	parameter "_file_URL"="http://server.domain.com/dir/"
	add prefetch item {"name=" & parameter "_file_name" of action & " sha1=" & parameter "_file_sha1" of action & " size=" & parameter "_file_bytes" of action & " url=" & parameter "_file_URL" of action & parameter "_file_name" of action}
	collect prefetch items
end prefetch block
1 Like

Relevance substitution is NOT performed on the prefetch action command lines.

Reference.

1 Like

Well that’s just silly… :rage:

It has to do with when and where the prefetches are processed vs when the relevance substitution is processed.


There is an explanation in the referenced document:

Relevance substitution is NOT performed on the prefetch action command lines. This is because these actions are scanned by other components that deliver the downloads and these other components run on different machines which do not share those client's evaluation context.

https://www.ibm.com/support/knowledgecenter/SS2TKN_9.5.0/com.ibm.bigfix.doc/Platform/Action/c_prefetch.html

It’s still silly :stuck_out_tongue: Never said it wasn’t reasonable.

Would be neat if there was a way to still allow the pre-stage of the content and still wrap in the “if {…}”, AND use variable substitution.

But that’s having your cake and eating it too I suppose.

1 Like

You can use IF within a prefetch block I believe. Example: https://bigfix.me/fixlet/details/3967

Also, collect prefetch items is implied and unneeded directly before end prefetch block, which I didn’t realize at first.

You can actually use collect prefetch items to cause the client to download stuff before continuing with the prefetch block.

1 Like

There are several other options to consider in this post. Prefetching / downloading a dynamically named file I’ve used all of them successfully in different circumstances.

Generally I would recommend against using no hash prefetch item or wget/curl to download content unless there is no better solution due to those options being less secure and not able to make use of the Relay Caching mechanism.

There might be reasons to use them, but only with caution.

Agree, not the normal situation. However I’ve found use cases with business ERP systems, for example, where those alternative means are extremely helpful. Dynamic urls by business attributes (brand, country, location, subnet, etc) can be super useful in select circumstances.