Redirect output from a command to a text file using a parameter

(imported topic written by SystemAdmin)

Is it possible to redirect output from an executed command to a text file using a parameter?

Example:

parameter “OUTPUTLOG” = “{(value of variable “SystemDrive” of environment) & “\Test” & (computer name) & “_TestOutput.txt”}”

waithidden cmd.exe /C {(pathname of system x32 folder) & “\cscript.exe”} /NoLogo {(pathname of system x32 folder) & “\IISBack.vbs”} /List >> “{parameter “OUTPUTLOG”}”

Results (computer name was changed for security reasons):

Parameter: “OUTPUTLOG” = “C:\Test\ComputerName_TestOutput.txt”

waithidden cmd.exe /C C:\Windows\system32\cscript.exe /NoLogo C:\Windows\system32\IISBack.vbs /List >> "

I cannot seem to get BigFix to interpolate the parameter “OUTPUTLOG” before passing it to the CMD prompt.

Any help would be greatly appreciated.

(imported comment written by BenKus)

Maybe this will help: http://forum.bigfix.com/viewtopic.php?id=1914

Ben

(imported comment written by SystemAdmin)

Thanks for your reply, Ben.

I did see that article previously; if I hard code the path and file name for the output file, or if I use system variables on the fly, the redirection does work as expected. However, it fails if I set the log file to a parameter and then reference it. I would like to use a parameter since I reference it throughout my action script.

This works:

waithidden cmd.exe /C {(pathname of system x32 folder) & “\cscript.exe”} /NoLogo {(pathname of system x32 folder) & “\IISBack.vbs”} /List >> “{(value of variable “SystemDrive” of environment) & “\Test” & (computer name) & “_TestOutput.txt”}”

Thanks again.

Dean

(imported comment written by BenKus)

Very strange… The relevance substitution is supposed to be a straight string replacement and I am not sure why it isn’t working…

Does the the “{parameter “OUTPUTLOG”}” work in other parts of the relevance?

What version of the agent are you using?

Ben

(imported comment written by SystemAdmin)

We’re using BES Client Version 7.0.1.376.

Using “{parameter “OUTPUTLOG”}” does work elsewhere in the script for simple output such as:

dos echo OUTPUTLOG= “{parameter “OUTPUTLOG”}” >> “{parameter “OUTPUTLOG”}”

As of this afternoon, I was able to get the code to work as expected. I believe I was running into 2 issues: 1) The Fixlet Debugger doesn’t seem to like the code. 2) A problem with quotation marks.

Here’s sample code that works as a task but not in the Fixlet Debugger:

dos if not exist {(value of variable “SystemDrive” of environment) & “\Test”} md {(value of variable “SystemDrive” of environment) & “\Test”}

parameter “OUTPUTLOG” = “{(value of variable “SystemDrive” of environment) & “\Test” & (computer name) & “_TestOutput.txt”}”

dos if exist “{parameter “OUTPUTLOG”}” del “{parameter “OUTPUTLOG”}”

dos echo OUTPUTLOG= “{parameter “OUTPUTLOG”}” >> “{parameter “OUTPUTLOG”}”

dos echo. >> “{parameter “OUTPUTLOG”}”

dos echo BES Clinet Version = {version of client} >> “{parameter “OUTPUTLOG”}”

dos echo. >> “{parameter “OUTPUTLOG”}”

waithidden cmd.exe /C {(pathname of system x32 folder) & “\cscript.exe”} /NoLogo {(pathname of system x32 folder) & “\IISBack.vbs”} /List >> “{parameter “OUTPUTLOG”}”

Here’s the final code that worked for me:

//---------------------------------------------------------

// Set some parameter variables.

//---------------------------------------------------------

parameter “IISBKUPS” = “{(value of variable “SystemDrive” of environment) & “\LOGS\IISAudit\IISBackups” & (computer name) & “_IISBackupsExtract.txt”}”

parameter “SCRIPTHOST” = “{if exists (x64 registry) then (pathname of system x64 folder) & “\cscript.exe” else (pathname of system x32 folder) & “\cscript.exe”}”

//---------------------------------------------------------

// Remove old files if they already exist.

//---------------------------------------------------------

dos if exist “{(value of variable “temp” of environment) & “\Adsutil.vbs”}” del “{(value of variable “temp” of environment) & “\Adsutil.vbs”}”

dos if exist “{(value of variable “temp” of environment) & “\IISAudit.vbs”}” del “{(value of variable “temp” of environment) & “\IISAudit.vbs”}”

dos if not exist {(value of variable “SystemDrive” of environment) & “\LOGS\IISAudit\IISBackups”} md {(value of variable “SystemDrive” of environment) & “\LOGS\IISAudit\IISBackups”}

dos if exist “{parameter “IISBKUPS”}” del “{parameter “IISBKUPS”}”

//---------------------------------------------------------

// Download file(s)

//---------------------------------------------------------

download http://someserver:port/Win/IISAudit.vbs

download http://someserver:port/Win/Adsutil.vbs

//---------------------------------------------------------

// Move files from download folder.

//---------------------------------------------------------

move __Download\Adsutil.vbs “{(value of variable “temp” of environment) & “\Adsutil.vbs”}”

move __Download\IISAudit.vbs “{(value of variable “temp” of environment) & “\IISAudit.vbs”}”

//

// Run Script

//-----------------------------

if {exists x64 registry}

action uses wow64 redirection false

waithidden cmd.exe /C {parameter “SCRIPTHOST”} /NoLogo “{(value of variable “temp” of environment) & “\IISAudit.vbs”}”

waithidden cmd.exe /C {parameter “SCRIPTHOST”} /NoLogo {(pathname of system x32 folder) & “\IISBack.vbs”} /List >> “{parameter “IISBKUPS”}”

action uses wow64 redirection true

else

waithidden cmd.exe /C {parameter “SCRIPTHOST”} /NoLogo “{(value of variable “temp” of environment) & “\IISAudit.vbs”}”

waithidden cmd.exe /C {parameter “SCRIPTHOST”} /NoLogo {(pathname of system x32 folder) & “\IISBack.vbs”} /List >> “{parameter “IISBKUPS”}”

endif

//-----------------------------

// Script Complete

//-----------------------------

Thanks again for your help, Ben; I appreciate it.

Dean