Waithidden cmd /c does not working properly

Hi,

I am executing the below command on windows machine through bigfix action. Below command is just to check whether the machine on boarded to McAfee Server or not

waithidden cmd.exe /C sqlcmd -v servername= “Machine Name” -S “Machine Name” -U username -P password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt”

But in some of the machines it gave exit code 0 and in some of the machines it gave exit code 1

Any Suggestion for this?

Command started - waithidden cmd.exe /C sqlcmd -v servername= “Machine Name” -S “Machine Name”" -U username -P password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” (action:12354)
** Command succeeded (Exit Code=0) waithidden cmd.exe /C sqlcmd -v servername= “Machine Name” -S “Machine name” -U username -P password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” (action:12354)**

Command started - waithidden cmd.exe /C sqlcmd -v servername= “Machine Name” -S “Machine Name”" -U username -P password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” (action:12354)
** Command succeeded (Exit Code=1) waithidden cmd.exe /C sqlcmd -v servername= “Machine Name” -S “Machine name” -U username -P password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” (action:12355)**

There is an additional set of surrounding doublequotes that can be used,that is specific to CMD.exe only, that may be helpful. You can also redirect the stderr stream to show error messages in the output file - you may find sqlcmd is not available on some systems, or the database is not available, etc

Try

waithidden cmd.exe /C "sqlcmd -v servername= "Machine Name" -S "Machine Name" -U username -P password -i "c:\Support\sql\mycloud.sql" > "c:\temp\sqlcmd.txt" 2>&1"

Also, think about wow64 redirection. By default, BigFix actions run as 32bit and by not specifying path to the tools you are relying the tool to exist under path locations within 32bit CMD process too which may not be the case. Might want to disable wow64 redirection within your action.

1 Like

Still having same issue. Below is the complete action script. Because of some security reasons i have deleted the server name and SHA value

// Write Parameter Here
action parameter query “Client_Name” with description “Please enter the Client Machine name which need to be OnBoarded” with default value ""
action parameter query “Mcafee_Server_Name” with description “Please enter the Server Machine name which need to be Targeted for OnBoarding” with default value “”

waithidden “C:\Program Files\McAfee\Agent\maconfig.exe” -custom -prop2 "boarding"
waithidden “C:\Program Files\McAfee\Agent\cmdagent.exe” /p

parameter “start” = "{now}"
pause while {now < ((parameter “start” of action) as time) + (“00:00:900” as time interval)}

waithidden cmd.exe /C “sqlcmd -v servername= “{parameter “Client_Name”}” -S “{parameter “Mcafee_Server_Name”}” -U Username -P Password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” 2>&1”

if {exists file “sqlcmd.txt” whose (exists line whose (it contains “OK”) of it) of folders “c:\temp”}

wait “C:\Program Files\McAfee\Agent\maconfig.exe” -custom -prop2 ‘’’'
wait “C:\Program Files\McAfee\Agent\cmdagent.exe” /p
wait msiexec /x “c:\temp\msodbcsql.msi” /QN
wait msiexec /x “c:\temp\MsSqlCmdLnUtils.msi” /QN
folder delete “C:\Support”

else

parameter “start1” = "{now}"
pause while {now < ((parameter “start1” of action) as time) + (“00:00:900” as time interval)}

prefetch c6685f49c83f495365092af4e66699f3f661c8fd sha1:c6685f49c83f495365092af4e66699f3f661c8fd size:309 http://USLVDST117.com:52311/Uploads/c6685f49c83f49566699f3f661c8fd/mycloud.sql.tmp sha256:f421b4010bbfc77ccc38d90bb09e0ae813a07e9fcdeacefbf772c6
extract c6685f49c83f49536699f3f661c8fd “C:\Support\sql”

waithidden cmd.exe /C “sqlcmd -v servername= “{parameter “Client_Name”}” -S “{parameter “Mcafee_Server_Name”}” -U Username -P Password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” 2>&1”

if {exists file “sqlcmd.txt” whose (exists line whose (it contains “OK”) of it) of folders “c:\temp”}

wait “C:\Program Files\McAfee\Agent\maconfig.exe” -custom -prop2 ‘’’'
wait “C:\Program Files\McAfee\Agent\cmdagent.exe” /p
wait msiexec /x “c:\temp\msodbcsql.msi” /QN
wait msiexec /x “c:\temp\MsSqlCmdLnUtils.msi” /QN
folder delete “C:\Support”

else

parameter “start2” = "{now}"
pause while {now < ((parameter “start2” of action) as time) + (“00:00:900” as time interval)}

prefetch c6685f49c83f495365699f3f661c8fd sha1:c6685f49c83f4e66699f3f661c8fd size:309 http://USLVLcom:52311/Uploads/c6685f492af4e66699f3f661c8fd/mycloud.sql.tmp sha256:f421b4010bbfc77ccc38dbd90bb09e0ae813a07e9fcdeacefbf772c6
extract c6685f49c83f49af4e66699f3f661c8fd “C:\Support\sql”

waithidden cmd.exe /C “sqlcmd -v servername= “{parameter “Client_Name”}” -S “{parameter “Mcafee_Server_Name”}” -U Username -P Password -i “c:\Support\sql\mycloud.sql” > “c:\temp\sqlcmd.txt” 2>&1”

if {exists file “sqlcmd.txt” whose (exists line whose (it contains “OK”) of it) of folders “c:\temp”}

wait “C:\Program Files\McAfee\Agent\maconfig.exe” -custom -prop2 ‘’’'
wait “C:\Program Files\McAfee\Agent\cmdagent.exe” /p
wait msiexec /x “c:\temp\msodbcsql.msi” /QN
wait msiexec /x “c:\temp\MsSqlCmdLnUtils.msi” /QN
folder delete “C:\Support”

else
wait msiexec /x “c:\temp\msodbcsql.msi” /QN
wait msiexec /x “c:\temp\MsSqlCmdLnUtils.msi” /QN
folder delete "C:\Support"
exit 100
endif
endif
endif

I don’t have McAfee, I don’t know what’s in that SQL script you’re trying to run, don’t know how your SQL Server is set up, don’t have those MSI packages, and don’t know whether what you’re trying to do even works outside of BigFix. But we can still do some of the basic troubleshooting on this.

The first step would be, that the ‘cmd.exe’ command you’re running saves the output and error messages from the command in “c:\temp\sqlcmd.txt”. What’s in that file? Does the file exist? Does it contain an error message?

An approach I use for troublseshooting CMD oddities is to use wait CMD.exe /k "your commands here" via the FixletDebugger. This will present you the CMD prompt of the command as its runs and let you see if there are any errors or syntax/formatting issues thrown by the command. You do have to manually exit the CMD prompt to get control back to the debugger (or use run to avoid that)

4 Likes

yes it was giving me error, however issue got fixed when i made fixlet in different way by using Powershell command.

1 Like

If you want to redirect output and error to a text file - please use the following syntax:

dir file.xxx 1> output.msg 2>&1