msdeploy command throwing error when executed from .bat file - batch-file

Following is my msdeploy command to copy files from one server to another (server1 to server2) successfully:
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server1:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server2:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
I have one more similar command exactly as above to transfer files between server3 and server4 as well which is working successfully from command prompt. Whereas when i put one of these commands or both in a .bat file, getting the following error:
Below is the exact content of my batch file:
#ECHO OFF
CD C:\Program Files\IIS\Microsoft Web Deploy V3
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server1:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server2:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server3:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server4:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
I tried running as an administrator , still the same problem. To my surprise the exact same commands with some other servers are working fine from the .bat file as well.

Executing the batch file with cmd /c is working. Usually cmd /c needs to be used to return control to the bat file even though there are fatal errors. Don't know the exact reason why only this works because there are no fatal errors in my case.
check this for more information A .bat File, "Call" or Not to "Call", That is the

Related

Using 'for' command to find and download the latest file on SFTP server in PSFTP

I have gone through the following guide to set up an SSIS package to retrieve a text file located on an SFTP server:
https://www.mssqltips.com/sqlservertip/3435/using-sftp-with-sql-server-integration-services/
To summarize, the SSIS package executes PSFTP.exe (A PuTTY tool) which takes the necessary credentials to connect to the server. It also takes a batch file that it executes after connecting. This batch file contains the commands to retrieve the desired text file. To start from the guide, it simply contains a cmd command to change directory, and a get command to retrieve the file:
cmd DataDump
get TeleMarketingResults.txt
All of this works fine.
The issue arises when I try to make this batch file logic more complex as it does not seem to recognize basic keywords. For instance, I would like to modify it to retrieve the most recent file, so I tried adding this:
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
echo The most recently created file is %LAST%
but then I get these errors:
psftp: unknown command "for"
psftp: unknown command "echo"
If I execute the batch file manually in a local directory, it works. The issue only occurs when passing it as a parameter to PSFTP.exe. Why is this?
psftp script file can contain psftp commands only. for, set or dir are not psftp commands.
There's hardly any reasonable way to retrieve latest file using psftp. You would have to do it in two steps. First to retrieve listing and store it to a file. Then parse that file using some smart batch file commands to find the latest files. And then run psftp again to download that file. It is cumbersome and ineffective as it requires two connections.
You better use a more powerful SFTP client. For example it's trivial with my WinSCP SFTP client. See
Question WinSCP select most recent file or
WinSCP article Downloading the most recent file.

Command Line Installation with SCCM 2012

I have a few applications that I am trying to deploy with SCCM 2012 but the installations are failing through the application catalog. So what I have for the deployment type is a script installer. I have "cmd.exe" (Without quotations) in the Installation program field and "Installer.bat" in the installation start in field.
When I look at the ccmcache folder, all the contents over that application are there but the following error displays the Software Center:
0x8007010B(-217024629)
I have done some reading online and the "10B" is a common command line error for invalid directory. I have tested the batch file when hard coding a path but my question is, how can I edit the batch file or SCCM to pull from the CCMCache path where the files are downloaded to on the local client? Currently the Batch File is simply:
#echo off
ApplicationName.exe
Do I need to edit the file to cd into the CCMCache folder where the files are placed? How can I get the batch file to run the executable that is downloaded to the CCMCache folder?
Thank You!
You need to have the full path to the installation in your script
#echo Off
\\path to .exe
The way the command is written will not be able to find the .exe file. You need to add the full unc path to the .exe into your .cmd file. You should have your installation .exe and .cmd file in the same location on the distribution share
Recommended Solution:
Before starting, since you are only launching an exe with your batch file, I would recommend just using your ApplicationName.exe as your command line parameter in SCCM instead of using a batch. This will eliminate the need to engineer any further.
Modifying the existing solution to work:
If you do still want to use a batch file, keep a few things in mind. The syntax you are using to launch the batch file will not work. I would recommend just using the batch file name "installer.bat" as your command line. If you still want to preface the batch with the cmd.exe, you absolutely need to use the /c switch with it
cmd.exe /c installer.bat
If you don't use /c the console host will only open to a promopt and not execute your batch.
This is not an ideal solution though because using "cmd.exe /c" will set your working directory to the location of cmd.exe (ie "C:\windows\system32") and since your content is staged in ccmcache, you will need to specify its location within your batch. To do this, you would use %~dp0 variable which gives you the directory the current batch is running from. This means modifying your batch to read
#echo off
%~dp0ApplicationName.exe

MSBuild execution fails through jenkins whereas same command runs properly through command prompt

I tried to execute the below command from Jenkins, and I got below error. I tried to print the command and executed the same command through cmd.exe and it runs successfully. I checked the folder permission and it is having the write permission. I ran jenkins using war file and saw it is executing under the same user as cmd.exe is running
Command that is executed on both jenkins and cmd.exe is,
"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" "d:\jenkins\workspace\NewTestItem\App\abc.sln" /t:rebuild /p:PackageLocation=d:\jenkins\workspace\NewTestItem\iisPackageDeploymentDir\26\ /p:DeployOnBuild=True /p:Configuration=Release /m /v:d /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false
Error which I am getting in jenkins
Microsoft.Common.CurrentVersion.targets(3821,5): error MSB3021: Unable to copy file "d:\jenkins\workspace\NewTestItem\App\mgmt\UserGuide\US\help.pdf" to "bin\mgmt\UserGuide\US\help.pdf". Access to the path 'bin\mgmt\UserGuide\US\help.pdf' is denied.
Note : Solution contains multiple project

Executing FART.exe (find and replace text) commands on remote server through SSH

I'm executing a batch file on a remote server from our build server (Jenkins) through SSH. The batch file uses fart.exe commands to find and replace text. I have placed the fart.exe in C:\Windows\System32 and I'm invoking it as C:\windows\system32\fart.exe in the batch file.
The command works perfectly fine oin the remote server, but when invoking through SSH I get an error in the Jenkins log as:
'"C:\windows\system32\fart.exe"' is not recognized as internal or external command.
This is the only error I'm getting and the other commands successfully execute in the batch script. Both of the servers are Windows Server 2012 R2.
I tried adding the path to system variable but it didn't work.
This is how the Fart.exe is used in the batch script.
for /R "%BACKUP_SOURCE%" %%G in (%ConfigFile%) do (
"C:\windows\system32\fart.exe" "%%G" %PlaceHolder% %AppPath%
)
Invoking From Jenkins
I don't think the way i invoke the batch script do matter, because it is done trough the Jenkins SSH plugin. The batch script get invoked successfully. The error i get is from when executing the Fart.exe
I tried invoking a different command of an exe located in the same path, and that is successfully invoked. so i guess the issue is isolated to FART.EXE.

Where can I find output log file of a setup generated by IExpress

I have a exe file created via IExpress. This file contains 1 msi file, 1 setup.exe file and a batch file with those commands:
C:\Windows\System32\msiexec.exe /i pitming.msi /passive
setup.exe
When I manually launch the batch, everything runs fine. But once I put everithing in the exe, nothing happen. So I'm trying to find what is wrong, but I don't know where to find a log file containning the error.
Can someone help ?
Thx,
If you want the log out of the MSI you need to edit the line to:
C:\Windows\System32\msiexec.exe /i pitming.msi /passive /l*v %temp%\pitming.log
and you'll at least get some logging out of it.
What command are you using to launch the batch file? You might find that you need to make the post install command to be:
C:\Windows\System32\cmd.exe /c mybatchfile.bat
As far as the setup.exe goes, that probably has its own logging options.

Resources