Script Timing Out in MaxFocus Remote Management

Sometimes a script times out because it really is trying to do more than is possible in the time allowed. But what if a script runs fine in the command shell, finishing in just a few seconds, but it times out in MaxFocus even when given five or fifteen minutes?

Checking for the Error Buffer Limit Issue

We’ll use the technique described in Debugging Scripts in MaxFocus Remote Management to run the script from a command prompt using the MaxFocus RM script runner task_start.js.

First, try writing the script output to a text file when run from MaxFocus task_start.js—the greater than sign (>) redirects output:

cscript "C:\PROGRA~2\ADVANC~1\task_start.js" 946 "92068.cmd %IT_Scripts%Helpers > C:\Users\<MyUser>\Desktop\92068_output.txt"

Compare the results of 92068_output.txt to the results of running 92068.cmd directly from the command prompt. One thing you may notice is that the text file does not include error messages like “Access is denied” and “The process cannot access the file because it is being used by another process.” This is because the default is to show standard output (StdOut) but not error output (StdErr).

In fact, there is an obscure issue where if a script generates lots of error messages and the script it not allowed to show those, it will hang. Note that “a lot” of error messages may be normal, for example if you’re deleting temp files, some of which will be in use. But apparently, when run from a Windows Scripting Host Exec method, the output is limited to 4KB.  (See MSKB 9602466.)

To confirm that this is your issue, run the script like this to create separate standard and error logs:

cscript "C:\PROGRA~2\ADVANC~1\task_start.js" 946 "92068.cmd %IT_Scripts%Helpers > C:\Users\<MyUser>\Desktop\92068_output.txt 2>C:\Users\<MyUser>\Desktop\92068_errors.txt"

Or run the script like this to create a combined standard and error log:

cscript "C:\PROGRA~2\ADVANC~1\task_start.js" 946 "92068.cmd %IT_Scripts%Helpers > C:\Users\<MyUser>\Desktop\92068_output.txt 2>&1"

Note the 2>&1 indicating to send the StdErr stream back to the StdOut stream.

If the script is no longer hanging when run this way, you’ll know that this 4KB buffer limit is your issue.

Solving the Timeout in MaxFocus

Unfortunately, the only way to solve this issue for all scripts would be to modify MaxFocus’s task_start.js to output both StdOut and StdErr output while running the script rather than after execution. For example, this line

sCommandExec = sCommand + sLogParam;

could be modified to be

sCommandExec = sCommand + sLogParam + " > temp_output.txt 2>&1";

That temp_output.txt would need to be picked up for output in the dashboard.

Until LogicNow rewrites task_start.js, the only solution is to modify your script such that each line that might write to StdErr redirects error output to StdOut. That means you must add 2>&1 at the end of the line that might generate errors. So for example, this line to delete files in C:\Temp

del C:\Temp\*.*

becomes

del C:\Temp\*.* 2>&1

Once your script is modified to write only to StdOut, it should no longer hang in MaxFocus.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.