I want to execute .sql file at /x/y/z location of a UNIX server, using ANT script from my local Windows XP system. The .sql files are at UNIX server.
I have used the below ant target from my Windows XP system:
<target name="execute" >
<sshexec host="hostname"
username="UNIX system username"
keyfile="/export/home/appldev/.ssh/id_dsa"
commandResource="psql -f /u01/appldev/devappl/po/11.5.0/reports/xxbt/1.0.0/sql"/>
</target>
I have tried the below post keyfile error:
<target name="execute" >
<sshexec host="server_ip"
username="server_uname"
password="server_pass"
command="touch abc"/>
</target>
Got the error:
Buildfile: C:\Program Files\Java\apache-ant-1.8.1\build.xml
execute:
[sshexec] Connecting to server_IP:22
BUILD FAILED
C:\Program Files\Java\apache-ant-1.8.1\build.xml:49: com.jcraft.jsch.JSchExcepti
on: connection is closed by foreign host
Please help.
Use the Ant sql task.
<sql
driver="org.database.jdbcDriver"
url="jdbc:database-url"
userid="sa"
password="pass" >
<transaction src="data1.sql"/>
<transaction src="data2.sql"/>
<transaction src="data3.sql"/>
<transaction>
truncate table some_other_table;
</transaction>
</sql>
Edit:
To make the file accessible from your Windows XP box, you have lots of options. Which you choose depends on security settings, and how you feel about Ant prompting for passwords or storing passwords in a file on the file system.
You can expose the UNIX directory using Samba. Then you can mount that as a drive in Windows.
Expose the file using an FTP server on the UNIX side. Then use the FTP task to copy the file.
Use the scp task to copy the file using SSH.
Another alternative is to use the sshexec task to invoke the database client on the UNIX server.
<sshexec host="unix-host"
username="dbuser"
keyfile="${user.home}/.ssh/id_dsa"
commandResource="psql -f /x/y/z"/>
Related
tl;dr
robocopy has security problems copying from 'nas to nas'
The system detected a possible attempt to compromise security. Please
ensure that you can contact the server that authenticated you.
Summary
I'm running into "windows permission problems" when making backups using using the following:
powershell
robocopy
Windows 2008R2
Windows task scheduler
Task Scheduler output
Taskscheduler runs under user domain account "OPS\backupuser"
The script succeeds when it copies "from local drive" "to the backup nas"
However it fails when the script copies "from another nas" "to the backup nas"
In pictures...
Success: local drive --copy-to--> backup NAS
Fails: another NAS --copy-to--> backup NAS
Output
Robocopy fails with exit code 16.
Here is detailed output:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Thu Jul 07 22:22:11 2016
2016/07/07 22:22:26 ERROR 1265 (0x000004F1) Getting File System Type of Source \\app-data-nas.hosting.acme\bazapp$\production\foo_industries_prod\
The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you.
Source - \\app-data-nas.hosting.acme\bazapp$\production\foo_industries_prod\
Dest : \\dr-backup-nas\AppDR$\ALL_DR\FOO_INDUSTRIES_DR\foo_industries_prod\
Files : *.*
Options : *.* /NDL /S /E /COPY:DT /PURGE /MIR /B /NP /R:0 /W:1
------------------------------------------------------------------------------
Other points
1) Because I the environment is 'locked down', I could not run this from the command line, either as :
my own account
my own account with elevated command prompt
OPS\backupuser
2) I tried adding '/NODCOPY' , but robocopy failed; apparently we don't have the hotfix for this option.
Thanks in advance!
NAS drives are not Windows drives. You have to map to them uniquely and with certain admin privileges to make them "see" you're trying to copy stuff into them.
First map a drive to the NAS system using NET USE
Next copy the file(s) using ROBOCOPY thus...
robocopy <source path> <nas path> <file(s)> /s /j /r:2 /w:5 /log+:robocopy.log
Place it all inside a CMD file and run it from a Task Scheduler on your Windows server.
>
>
>NAS drives are not Windows drives. You have to map to them uniquely and with certain >admin privileges to make them "see" you're trying to copy stuff into them.>
>
>First map a drive to the NAS system using NET USE
>
>Next copy the file(s) using ROBOCOPY thus...
>
>robocopy <source path> <nas path> <file(s)> /s /j /r:2 /w:5 /log+:robocopy.log
>Place it all inside a CMD file and run it from a Task Scheduler on your Windows server.
>
You forgot:
/FFT #":: assume FAT File Times (2-second granularity)" -ensures the copy ignores OS file system while copying in ROBOCOPY
/Z #":: Includes LARGE file copy restart" - restarts large file copying where the copy left off in the file, instead of starting over again. Like in a 500 GB file it restarts at the byte the copy stopped at, in case you need to schedule offline copying and don't want large files to prevent the copy progression (will ONLY start over if the file date changed!)
/xo #"exclude older files" -copies all new files - something useful to retry copies in Scheduled task Job of Robocopy...
All these are useful in NAS copying... as they tend to have issues resolved by these switches in ROBOCOPY.
I'm looking for some help/direction and am generally baffled as this must be a common issue that people face (i.e. there should be an straight forward solution!).
I'm deploying a web site remotely using TeamCity, MSBuild and WebDeploy/MSDeploy. I also wish to run some scripts on the remote server that I'm deploying to. ... How do people generally do this?! I just want to automate some everyday tasks remotely on ther server e.g. backing up files or similar.
Is it a case of:
Using MSDeploy to remotely run some scripts like here, but then how do I transfer the scripts to the remote server as part of the automated deploy??
Starting some sort of PowerShell session and remoting into the server this way?
Some sort of ssh-ing or another way?
FYI these are the params I use for MSBuild and MSDeploy to the remote server (they work fine):
/p:Configuration=TeamCityLiveRelease
/p:OutputPath=bin
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:ContinueOnError="false"
/p:MSDeployPublishMethod=WMSVC
/p:MsDeployServiceUrl=https://MY.SITE:PORT/msdeploy.axd
/p:DeployIisAppPath=my.iis.site.here
/p:AllowUntrustedCertificate=True
/p:Username=FOO
/p:Password=baaa
Ideally I'd like to write a nice command line script and do something like (about as pseudo as it comes sorry!):
Log in to "http://some.server.ip" -username "user" -password "something"
run script "echo this is a remote script running"
I think psexec is the tool you're looking for: http://technet.microsoft.com/en-us/sysinternals/bb897553
In case anyone is interested: it is possible to use MSDeploy to carry out scripts on a remote computer (a script called MYSCRIPT.bat here). If you have an admin account on the remote server then it can be done using the following arguments:
"c:\program files\iis\microsoft web deploy\msdeploy.exe"
-verb:sync
-source:runCommand="C:\MYSCRIPT.bat",
waitInterval=5000,waitAttempts=1
-dest:auto,
computerName=https://IP.ADDRESS.HERE:PORT/msdeploy.axd?site=IIS.SITE.NAME.HERE,userName=MYUSERNAME,password=MYPASSWORD
-verbose
-allowUntrusted
I'm currently using CruiseControl.NET to automate my build. We have two different ways to build a solution in my build environment - one is through the Keil uVision4 IDE, the other is through Visual Studio 2008.
I've successfully gotten the Visual Studio solution to build properly using CruiseControl.NET and have created a batch file which properly uses Keil's uVision command line interface to compile my uvproj Project (compilation details here).
Problem Description
1) I can successfully execute the build script on my Windows 2008 server and build the project if I create a command prompt with administrator privileges (I'm doing this manually - start -> run -> cmd with ctrl-shift-enter to run as admin).
2) However, if I create a command prompt without administrator privileges, and attempt to execute the batch file, the batch file won't work unless I accept the prompt asking me to confirm admin rights are required to run the batch script.
How do I automatically execute a batch file as an administrator through CruiseControl?
Is this something that could be automated using the RunAs command?
Technical details
1) The batch file being executed is pretty simple - it deletes the old output and re-makes the output, creating a build log file in the location below.
set BuildLogLocation=BuildLog\BuildLog.txt
echo on
cd ../..
cd PTM
rmdir /s /q output
mkdir output
mkdir BuildLog
C:\Keil\UV4\UV4.exe -r myProj.uvproj -o %BuildLogLocation%
echo ErrorLevel of build is %ERRORLEVEL%
echo build complete, see %BuildLogLocation%
2) Currently I'm looking to use the Exec functionality to run the Keil build script above:
<Exec>
<Command>C:\myProject\Build\KeilBuild\BuildScript.bat<Command/>
<buildTimeoutSeconds>600<buildTimeoutSeconds/>
<!-- Details about error codes can be found here:
http://www.keil.com/support/man/docs/uv4/uv4_commandline.htm -->
<successExitCodes>0,1</successExitCodes>
<Exec/>
Related questions:
How can I use a build server with Keil uVision4 (MDK-ARM), script a build, use a makefile? (Electrical Engineering)
Execute a command-line command from CruiseControl.NET (Stack Overflow)
Can you run CCService, the CruiseControl.NET Windows Service, as a user who has administrative permissions? I'd try that first.
If that doesn't work, I would use runas to run your script. You'll have to embed the administrative user's password in the script calling runas.
I know this is old but, Did you get an offical way to do it Via Cruise Control?
Normally I create this and call it to call other processes "As Admin".
Make a ".VBS" script with This in the contents:
Dim strBatchPath
strBatchPath = "PATH-TO-FILE.EXE"
Set runBatch = CreateObject("shell.application")
runBatch.shellexecute strBatchPath,,,"runas",1
That could be an option to people that can't find an official way
You could try psExec from sysinternals. If you don't need to run as a nt-authority account you should be able to use this in the same way as runas.
It allows you to pass in the username/password as a switch (if memory serves)
I have Discovered that when using PSEXEC and using the -h switch, it then "runs as admin" on destination
e.g.
psexec -h \ServerToRunOn /accepteula -u DOMAIN\USER -p PASSWORD "PATH-TO-FILE"
I am Using CC.Net to call a batch file with the above in. This will run that file as Admin
I have a sql script file which is 1.5GB
i want to run it but i cant use it using SQL Management Console, cause it can't load the file. I came up to the solution that run the query with SQLCMD utility but when i want to execute the file it returns (Failed to load resource file SQMCMD.rll)
sqlcmd -s (local) -i C:\myScript.sql
anyone knows what is the problem and how i can run this large script file ?
I had the same problem, and I have solved.
In my case the problem was I had installed more than one version of SQL (2005, 2008, 2012), and I had uninstalled the two first ones, so at this moment I only have the Sql Sever Express 2012.
After playing a lot of minutes I discovered that old installations left his respective sqlcmd.exe files in my machine, but the uninstall process removed the corresponding rll file.
When I hit in the cmd window the sqlcmd it seems the system tries to run the sqlcmd for one of the old sql installation.
Then I went to the folder of the installed version and that works.
It is (in my case, in your case you can find the file sqlcmd.exe):
1- cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn
Inside that folder, then
2- SQLCMD -d databaseName -i C:\MyScripts\specificScript.sql
And that did the trick!
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=228de03f-3b5a-428a-923f-58a033d316e1&displaylang=en
I'd download the sqlcmd installer and run it - see if that fixes you up.
It's under "Microsoft SQL Server 2008 Command Line Utilities".
The installer should create that file and you'll be set. You could also try to run osql, which is the older command line SQL utility.
Edit:
Try this:
Please check the permission on the sqlcmd.exe and sqlcmd.rll and make sure the user has the read&execute permission on them. You also could specify the full path of the sqlcmd.exe in the command, such as:
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" -L
I just had this problem on SQL Server 2008 R2. Reinstalling the Command Line Utilities from the Feature Pack is what did it. The trick is if you are on 32-bit only install the x86 package, but if you are on 64-bit install both the x86 and the x64 package. The reason for this being is that some SQL Server tools are only 32-bit which means that both C:\Program Files\Microsoft SQL Server\100\Tools\Binn and C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn are in your PATH variable in order to ensure all of the tools are accessible, which means either of them could be run, therefore both of them need to reinstalled to ensure you have them run properly.
In my case the issue arised after migrating from SQL Server 2008 R2 to SQL Server 2012.
The problem was pretty simple. It was the path. Just correct your SQL Server path in the System path pointing to the new directory.
I got a variant of this error in an Linux installation of the MS SQL Server CLI for Linux, which stated,
# bcp
Unable to load BCP resource DLL. BCP cannot continue.
# sqlcmd
Unable to load SQLCMD resource file(s)
I found that I had not followed the installation direction exactly, in that rather than modify the system PATH to add the installation directory (/opt/mssql-tools/bin), I had used 'install' to copy the binaries to /usr/local/bin without the corresponding /opt/mssql-tools/share directory.
for I in /opt/mssql-tools/bin/*; do install $I /usr/local/bin; done
When I removed those copies and did export PATH="$PATH:/opt/mssql-tools/bin" as the instructions show, then it worked.
# bcp
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[...]
# sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 17.1.0000.1 Linux
[...]
I have this trouble:
I am using VS 2008 Team Suite, and I have WinForms csproj. I want Publish it using ClickOnce.
In Publish Properties of csproj, I have these values:
Publishing Folder Location (web site,
ftp server, or file path):
C:\ClickOnce\Frk.Security.CarWin.WebInstall\Publicacion\
Installation Folder URL (if different
than above):
http://CHANGETHESERVER/carwinclickonce/Publicacion/
Publish Version: 1.0.0.0
Prerrequisites: Windows Installer 3.1,
.NET 35. sp1
Now, I publish and all is OK. I need deploy my app to several machines (Development, Preproduction, production environments...), and I use Msbuild...
<Microsoft.Sdc.Tasks.Folder.CopyFolder
Source="Publicacion"
Destination="$(Directorio_Destination)\Publicacion" />
I copy C:\ClickOnce\Frk.Security.CarWin.WebInstall\Publicacion\ to another machine, in folder (this folder is root of a Web Site)
\\desiis\c$\Webs\carwinclickonce\Publicacion\
(http://desiis/carwinclickonce/Publicacion/)
I use MSBUILD and Mage like this; variable $(ProviderUrl) = http://desiis/carwinclickonce/Publicacion/
<Target Name="PublishClickOnce">
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -pu $(ProviderUrl)" />
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -cf $(CertDir)\Frk.Security.CarWin_TemporaryKey.pfx" />
</Target>
Now, I have my publish.htm in http://desiis/carwinclickonce/Publicacion/publish.htm.
There are two links to install application:
1. ) http://desiis/Carwinclickonce/Publicacion/Frk.Security.CarWin.application
Everything is OK for this option.
) http://desiis/Carwinclickonce/Publicacion/Setup.exe
This option gets errors!
The errors are the following:
Error al intentar descargar
'http://CHANGETHESERVER/carwinclickonce/Publicacion/Frk.Security.CarWin.application'.
(FAILS when try download
'http....Frk.Security.CarWin.application')
Vea el archivo de registro de la
instalación que se encuentra en
'C:\DOCUME~1\xxxxxx\CONFIG~1\Temp\VSD5B7.tmp\install.log'
para obtener más información.
install.log contents:
The following properties have been
set: Property: [AdminUser] = true
{boolean} Property:
[ProcessorArchitecture] = Intel
{string} Property: [VersionNT] = 5.1.3
{version} Running checks for package
'Windows Installer 3.1', phase
BuildList The following properties
have been set for package 'Windows
Installer 3.1': Running checks for
command
'WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe'
Result of running operator
'VersionGreaterThanOrEqualTo' on
property 'VersionMsi' and value '3.1':
true Result of checks for command
'WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe'
is 'Bypass' 'Windows Installer 3.1'
RunCheck result: No Install Needed
Launching Application.
URLDownloadToCacheFile failed with
HRESULT '-2146697211' Error: Error al
intentar descargar
'http://CHANGETHESERVER/carwinclickonce/Publicacion/Frk.Security.CarWin.application'.
(FAILS when try download
'http....Frk.Security.CarWin.application')
Any ideas? Can I use Mage.exe commands? How can I modify setup.exe?
Update:
use msbuild for using setup -url=http://desiis/....
<Exec Command="$(PublishDir)\setup -url=$(ProviderUrl)" />
Another problem is that after using the /url switch to change out the URL, a message box appears for manually confirming that the signature will be invalided for the assembly.
How can use setup -url=http://.... in silent mode?
How can I sign the setup.exe again?
My msbuild
<Target Name="PublishClickOnce">
<Exec Command="$(PublishDir)\setup -url=$(ProviderUrl)" />
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -pu $(ProviderUrl)" />
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -cf $(CertDir)\Frk.Security.CarWin_TemporaryKey.pfx" />
</Target>
To clarify, ClickOnce works. Your problem is with the setup.exe bootstrapper file that Visual Studio generates to install prerequisites. You use a bogus server name (CHANGETHESERVER) and change it later depending on what server you deploy to. The server name can easily be changed for the .application file but you're unsure how to fix the setup.exe file since it tries to launch http://CHANGETHESERVER/... after installs the prereqs. Is all this correct?
I'm not sure how to update your setup.exe file to point to the proper url. However, I wouldn't worry about updating it. I would go to Visual Studio, change "CHANGETHESERVER" to an actual server (like your Development server), and publish. The setup.exe that's generated will be good for the server you used. Keep a copy of that .exe and do the process again for your other servers (QA, Production, etc.). Deploy the server specific files to each server and you're done.
The setup.exe files aren't going to change unless you're adding/removing prerequisites. There's no need to generate and deploy a new one every time you deploy.
update:
Now, Publish and All is OK done. I need deploy my Publish in several machines (Development, Preproduction, production environments...), and I use Msbuild.
Then, using MSBUILD
<Microsoft.Sdc.Tasks.Folder.CopyFolder Source="Publicacion" Destination="$(Directorio_Destination)\Publicacion" />
I copy C:\ClickOnce\Frk.Security.CarWin.WebInstall\Publicacion\ to another machine, in folder (this folder is root of a Web Site)
\desiis\c$\Webs\carwinclickonce\Publicacion\
(http://desiis/carwinclickonce/Publicacion/)
I use MSBUILD and Mage like this; variable $(ProviderUrl) = http://desiis/carwinclickonce/Publicacion/
<Target Name="PublishClickOnce">
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -pu $(ProviderUrl)" />
<Exec Command="$(Mage) -u $(PublishDir)\Frk.Security.CarWin.application -cf $(CertDir)\Frk.Security.CarWin_TemporaryKey.pfx" />
</Target>