How to wait for download to finish in action

Hi
In my action I have a prefetch to download a file, and after that I have a move to move and rename the downloaded file to its right place and name. But the move fails, because the download is not finished when the move run, how can I get the move to wait untill the download is finnished.

ActionScript doesn’t move on past the prefetch until the prefetch has finished.

Can you post your script in here please?

this is the script:
begin prefetch block
add prefetch item name=agentdef sha1=8d70282f0c5cf5f844239ae3c7da78802aeb1e1f sha256=06669a4b924b156b798c26a6b7b39b459c66cba0dfa64a0599d3be68184308da size=2974 url=http://sf000lx90016.mgt000t.sif.jndata.net/var/opt/BigfixActionFiles/TQ/agentdef.def
end prefetch block

parameter “sourceReleaseDate” = "2020-07-15"
parameter “destfolder” = "D:\TeamQuest\data\production"
parameter “tq_temp_loc” = "C:\temp\TQScripts"
parameter “tq_log_tqrestart” = "{parameter “tq_temp_loc”}\tqrestart.log"
parameter “downloads_loc” = "C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads"
parameter “tqrestart_bat” = “{parameter “tq_temp_loc”}\tqrestart.bat”

if {not exists folder (parameter “tq_temp_loc”)}
folder create "{parameter “tq_temp_loc”}"
endif

if {exists file (parameter “tqrestart_bat”)}
delete "{parameter “tqrestart_bat”}"
endif

move “D:\TeamQuest\data\production\agentdef” "D:\TeamQuest\data\production\agentdef.old"
move “{parameter “downloads_loc” as string}\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f” “{parameter “destfolder” as string}\agentdef”

createfile until eofline

“%PROGRAMFILES(X86)%\TeamQuest\Manager\bin\tqmgr.exe” -shutdown
"%PROGRAMFILES(X86)%\TeamQuest\Manager\bin\tqmgr.exe" -service

eofline

move __createfile “{parameter “tq_temp_loc” as string}\tqrestart.bat”

wait cmd.exe /c “{parameter “tq_temp_loc” as string}\tqrestart.bat”

This is the error I get in logfile:

ActionLogMessage: (action:45894) Submitting download request
ActionLogMessage: (action:45894) Download url: 'http://sf000lx90016.mgt000t.sif.jndata.net/var/opt/BigfixActionFiles/TQ/agentdef.def
At 09:45:54 +0200 -
ActionLogMessage: (action:45894) Action signature verified for Execution
ActionLogMessage: (action:45894) starting action
At 09:45:55 +0200 - actionsite (http://sf000lx90016.mgt000t.sif.jndata.net:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded parameter “sourceReleaseDate” = “2020-07-15” (action:45894)
Command succeeded parameter “destfolder” = “D:\TeamQuest\data\production” (action:45894)
Command succeeded parameter “tq_temp_loc” = “C:\temp\TQScripts” (action:45894)
Command succeeded parameter “tq_log_tqrestart” = “C:\temp\TQScripts\tqrestart.log” (action:45894)
Command succeeded parameter “downloads_loc” = “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads” (action:45894)
Command succeeded parameter “tqrestart_bat” = “C:\temp\TQScripts\tqrestart.bat” (action:45894)
Command succeeded folder create “C:\temp\TQScripts” (action:45894)
Command succeeded move “D:\TeamQuest\data\production\agentdef” “D:\TeamQuest\data\production\agentdef.old” (action:45894)
At 09:46:05 +0200 -
Retry error, attempt 9 failed for MoveFile (C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f ,D:\TeamQuest\data\production\agentdef)
At 09:46:05 +0200 - actionsite (http://sf000lx90016.mgt000t.sif.jndata.net:52311/cgi-bin/bfgather.exe/actionsite)
Command failed (Move of ‘C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f’ to ‘D:\TeamQuest\data\production\agentdef’ failed (2 - File error “class FileNotFoundError” on “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f” : “Windows Error 0x2%: The system cannot find the file specified.”)) move “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f” “D:\TeamQuest\data\production\agentdef” (action:45894)
At 09:46:05 +0200 - CustomSite_JN_Custom_Site (http://sf000lx90016.mgt000t.sif.jndata.net:52311/cgi-bin/bfgather.exe/CustomSite_JN_Custom_Site)
Fixed - JN - TQ replace agentdef file (fixlet:45797)

It runs ok the 2. time I run it, because then the file is in the __Download lib

That folder path is missing some backslash characters.

The prefetch works, but you are trying to move something that doesn’t exist.

I would not set that up as a parameter anyway, my preference would be to copy (not move because of the known permission based issues with a Windows move, and the downloads folder gets tidied up automatically) and use the __Download location

copy __Download\\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f “{parameter “destfolder”}\agentdef”

I get this error:

Command failed (Relevance substitution failed) copy __Download\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f “{parameter “destfolder”}\agentdef” (action:45895)

Ther was som brackets that was wrong, but after correcting them I get the error back:

Retry error, attempt 9 failed for CopyFile (C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_JN_Custom_Site__Download\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f ,D:\TeamQuest\data\production\agentdef)
At 10:58:00 +0200 - actionsite (http://sf000lx90016.mgt000t.sif.jndata.net:52311/cgi-bin/bfgather.exe/actionsite)
Command failed (Copy of ‘C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_JN_Custom_Site__Download\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f’ to ‘D:\TeamQuest\data\production\agentdef’ failed (2 - File error “class FileNotFoundError” on “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_JN_Custom_Site__Download\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f” : “Windows Error 0x2%: The system cannot find the file specified.”)) copy __Download\8d70282f0c5cf5f844239ae3c7da78802aeb1e1f “D:\TeamQuest\data\production\agentdef” (action:45906)
At 10:58:00 +0200 -

But as I se it the downloaded file is placed in “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global__Cache\Downloads”

and not in “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_JN_Custom_Site__Download” as the __Download points to

The file name actually downloaded will be agentdef - that is what you have defined it to be in your prefetch statement.

the value you are using is the hash of the file and you are using an artifact that is part of the inner workings of the client.

copy __Download\agentdef “{parameter “destfolder”}\agentdef”

that did the trick, thanks