dtutil import ssis package from remote - sql-server

I am trying to import an ssis package (.dtsx) from one server to another remotely but I face a strange issue. (dtsx is on Server-02 and need to be imported on Server-01)
Let me explain with 3 commands :
Running on Server-01
osql -E -h -Q "select name from [msdb].[dbo].[sysssispackages] where name like '%MIC%'"
This returns nothing, my package is not imported yet, that's ok.
I have a .bat file on Server-01 which contains the following command :
"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET
DTSX is located in D:\ on Server-02, .bat file is located in D:\ on Server-01.
This bat file must be run in order to import the ssis package.
Then running on Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
It returns successful state. But then when I run again on Server-01 my osql command, it still returns 0 result. It seems the package hasn't been imported...
We could think that the bat file isn't working but if I run the bat file directly by double clic on Server-01, it also runs successfuly. Then I do the osql select, it returns 1 result, the package has been imported successfuly.
At this moment, I thought that the bat script was simply not executed remotely. So I changed it a little.
echo "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET > D:\debug.txt
Then from Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
D:\debug.txt has been successfuly created on Server-01 which means the bat script also executed well...
Any idea of what could happen in my case ?

Related

How to Run SSIS Package Using Task Scheduler and Batch File

I have a windows batch file that looks like this:
"C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\DTExec.exe" /FILE
C:\SSIS\CARS\CARS\PCarsCallMonthlyCount.dtsx /DECRYPT pswrd /CHECKPOINTING OFF
When I run code from the command prompt the SSIS package runs with no errors. I then created a scheduled task to run and call the same batch file. The task runs but does not error out or end.
So I then open the batch file from the command prompt and I get this error "Missing argument for option "file". The execute Package Utility application then starts and waits for some input.
So I assume I am missing something in the command and that is why the task does not complete. How can I fix this?
If the command line is exactly how you have it in the batch file, you need to make it all on one line. It is not getting the second part of /FILE which is your .dtsx file.

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.

Using SSIS execute process task to run a batch file

I was tasked to execute a batch file using SSIS "execute process task".
FYI,The batch file(named test.bat) uses PsExec command to call a runthisboy.bat file on a remote webserver to refresh the appPool. Here is what I wrote in the test.bat:
psexec -d -i -s \\webserver1 -u domainName\myID -p myPassword "C:\Documents\runthisboy.bat"
After I run the SSIS package, there is an error message shows up:
[Execute Process Task] Error: In Executing "C:\Windows\System32\cmd.exe" "/c C:\Users\myName\Desktop\test.bat" at "", The process exit code was "1" while the expected was "0".
But if I use this SSIS package to run other .bat file, like:
xcopy /d /y "C:\Users\myName\Desktop\sample.txt" "C:\documents"
It runs without any problems.
If anyone can give me some clue about what is happening here, I will be so thankful!

SQL Server agent for scheduling SFTP using WinSCP under SSIS

I have a batch script which generates a WinSCP upload script to upload a file to an SFTP location. Now when I run the batch file via command prompt - it runs successfully and loads it. I called the same thru SSIS Execute process task - it runs successfully and loads it. Now when I put the same on SQL Agent - I tried the following two options:
Using Operating System (CmdExec) - cmd.exe /c "\.bat"
Added the SSIS package to SSISDB and added it as a job step.
With both the above options the job showed a successful run. However the file is not uploaded! Any ideas on what is happening?
Here's my batch script:
echo off
SET winscp=C:\"Program Files (x86)"\WinSCP\WinSCP.com
SET stagingDirectory=\\<staging path>\
SET scriptPath=\\<ScriptPath>\UploadScript.txt
SET ftpHost=xx.xx.xx.xx
SET ftpUser=user
SET ftpPass=password
SET fileName=Test.xlsx
SET ftpFlags=
#REM ftpFlags: -explicit
echo deleting uploadScript if it already exists
IF EXIST %scriptPath% del /F %scriptPath%
IF EXIST %scriptPath% exit 1
echo Generating WINSCP Upload Script
>>%scriptPath% echo option batch abort
>>%scriptPath% echo option confirm off
>>%scriptPath% echo open sftp://%ftpUser%:%ftpPass%#%ftpHost% %ftpFlags%
>>%scriptPath% echo option transfer binary
>>%scriptPath% echo put %stagingDirectory%%fileName% /
>>%scriptPath% echo close
>>%scriptPath% echo exit
echo Launching WINSCP upload
start /wait %winscp% /console /script=%scriptPath%
As you start the WinSCP via the start (why?), the exit code is not propagated to the SSIS. So, you never learn, if the script fails. And it most probably fails.
You also should enable logging, so that you can see what's wrong.
You should use this code to propagate the WinSCP exit code to SSIS and to enable logging:
%winscp% /log=\\<ScriptPath>\UploadScript.log /script=%scriptPath%
exit /b %ERRORLEVEL%
(Note that the winscp.com does not have the /console parameter)
Anyway, one clear problem is that you do not specify an expected SSH host key in the script. When you run the script manually, you probably have the key cached in the registry of your Windows account. But under the SSIS a different account is used, and its host key cache is likely empty. You should add the -hostkey switch to the open command in the script to make the script independent on the cache. See Where do I get SSH host key fingerprint to authorize the server?
When testing the script, add the /ini=nul parameter to isolate the script from your configuration.
For this and other hints, when debugging WinSCP running under SSIS, see My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong?
And finally, see WinSCP SFTP Task for SSIS.
Your variable seems set incorrectly. To manage with a space in the path and into the variable you have to put in quotes the whole path or the whole variable.
i.e.
set "winscp=C:\Program Files (x86)\WinSCP\WinSCP.com"
echo start "%winscp%"
:: output: start "C:\Program Files (x86)\WinSCP\WinSCP.com"
or
set winscp="C:\Program Files (x86)\WinSCP\WinSCP.com"
echo start %winscp%
:: output: start "C:\Program Files (x86)\WinSCP\WinSCP.com"
Another point, you have to check this file: UploadScript.txt because your script adds new lines rather than remake the file.
change this line to >%scriptPath% echo option batch abort instead of >>%...
Ah, I did not pay attention to the IF EXIST.

Running powershell script on network machine

I am running a Powershell script from a bat file. These 2 files are placed on a network server and I am trying to run these on network server from my machine by accessing network server folder. I get following error:
CMD doesn't support UNC paths as current directories.
When I execute bat file , it tries to read script file from path
C:\Windows\System32
not from current directory which is set in bat file.
This script and bat file work fine when I run on my local machine.
I tried finding this on Google and possible solutions need to change some settings on network server which is not possible in my case.
What could be possible solution for this?
I am using PowerShell 2.0
Here is my bat file to run Powershell script
setlocal & pushd .
:getting current directory
cd /d %~dp0
Powershell.exe Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Powershell.exe . '%CD%\Hotfix-Automation-Installer.ps1' crpt
exit /B
It's like the message says: CMD doesn't support UNC paths as current directories, so you shouldn't use %CD% or . when you're working with UNC paths.
However, what's actually preventing your PowerShell script from being run is the single quotes around the path:
Powershell.exe . '%CD%\Hotfix-Automation-Installer.ps1' crpt
Single quotes are not valid quoting characters in CMD, so your script is actually trying to run the PowerShell script from a subfolder ' in the current directory. Which doesn't exist.
Change your script to this, and it should work just fine:
#echo off
powershell -ExecutionPolicy ByPass -File "%~dp0Hotfix-Automation-Installer.ps1" crpt

Resources