Running sqlplus inside cmd.exe using sshexec - ssh

I have cygwin installed on a remote windows server running oracle. I am trying to run sqlplus through an ANT file in Jenkins. I use sshexec to run the command below, but it doesn't work.
I am able to make it work when I login into SSH then first type in 'cmd' to switch to the windows command prompt, then entering the sqlplus statement below is successfull.
How can I replicate the above using scripts by running the sqlplus command below in cmd.exe or run cmd.exe first then execute the sqlplus command so it works like when I perform it directly in SSH.
<target name="compile.data">
<sshexec host="${ssh.hostname}"
verbose="true"
trust="true"
username="${ssh.username}"
password="${ssh.username}"
command="sqlplus ${db.username}/${db.password}#${db.hostname}:${db.port}:${db.sid} #${script.path}testscript.sql"/>
</target>
Thanks.

I have found the answer after to my question for refernce:
<sshexec host="${ssh.hostname}"
verbose="true"
trust="true"
username="${ssh.username}"
password="${ssh.username}"
command='cmd /C "sqlplus ${db.username}/${db.password}#${db.hostname}:${db.port}:${db.sid} #${script.path}testscript.sql"'/>

Related

Invoke jar on remote windows machine using SSH

I'm using Bamboo as a CI (living on an AWS linux box) and have setup an SSH task where by I wish to invoke a jar file on another, physical, Windows machine. I have setup an SSH client on the Windows machine (Dameware SSH) and have setup a user called admin / admin.
The jar file runs a tool called SeInterpreter to run interpret .json selenium tests into webdriver tests.
I have a lack of knowledge around the format for the shell script I need to run in order to invoke the jar on the remote machine. I have cobbled the following together:
ssh admin#L-IS03159.nt.ad.local cmd /c cd /d "c:/SeInterpreterB11" cmd /c java -jar SeInterpreter.jar --driver=Remote --driver.browserName=firefox --driver.url=http://L-IS03159.nt.ad.local:4444/wd/hub/ C:/seleniumBuilderPOC/tests/loadHomePageSearchHomepage.json
The error from Bamboo is:
23-Jul-2014 15:36:12 Unable to execute command or shell on remote system: Failed to Execute process.
23-Jul-2014 15:36:12 Result: exit code = -1
23-Jul-2014 15:36:12 SSH command failed. Failing build.
Can anyone see obvious errors in the script syntax?
Your command line has the following form:
ssh user#hostname cmd /c [cd command] cmd /c [java command]
Try the following form, instead:
ssh user#hostname cmd /c "[cd command] && [java command]"
&& is a command separator in cmd.exe.
You may run into issues with the quotation marks in cd /d "c:/SeInterpreterB11". Since there are no spaces in this path, the quotes aren't necessary. Consider removing them to avoid headaches dealing with quote escaping.

In command line, putty remote shell doesn't work, but in GUI, it does work

Using the GUI putty.exe, I can connect to my windows server and once it is connected, i can type any command like rename file or mkdir folder and they all work
However, using command line such as
putty -load test -m C:\users\test.txt
or using the GUI putty, but add 1 command to remote command in SSH under Connection, then the command doesn't get executed.
Can anyone explain to me why this is happening or how can i fix this? I am using FreeSSHd on windows 2008 server.
Not sure if this helps, but try adding the /bin/bash directly after your command in the text file. It will keep the window open and you can see what the output of the shell would be if you ran it from the gui.
; /bin/bash
For example if test.txt is running a script
bash myscript.sh
bash myscript.sh; /bin/bash
This is assuming bash.

Exec Task in MSBuild for execution of command on remote machine

I am using following command to install a service via MSBuild file. This works great
<Exec Command= 'c:\test\myService.Appservices.exe install' ContinueOnError='false' />
But the above command install the service on local machine. I want to install the service on a remote machine. How can I specify the machine name using this command?
As per Mike Vine's comment, MSBuild doesn't include tools for remote execution. You could however use something like psexec. e.g.
<Exec Command='psexec -accepteula -s \\RemoteServer "C:\Path To EXE on Remote Machine\my.EXE"' IgnoreExitCode="false" ContinueOnError="false" Timeout="600000" >
<Output TaskParameter="ExitCode" PropertyName="exitCode1"/>
</Exec>

Running commands on Remote machine using PsExec from Msbuild invoked via Jenkins

I am using psexec(with MSbuild Script) to run an xCopy on a server from Jenkins(Hudson). The command runs ok when run through Command Prompt(as System user), but gives the following error when tried using Jenkins. This is the command I am using from Msbuild script:
psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ..
Couldn't access :
Connecting to ...
**error MSB3073: The command "psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i " exited with code 6.**
I have tried too many options but no luck so far.
Does anyone tried the same using Jenkins? Help will be really appreciated.
Are there any other ways to achieve this using some other tools without any problem. Please share.
Just wanted to post the solution here, as I figured it after some time.
The Remote Machine should have this user added in the Administrators Group.
This will resolve the connection issue. :)

How to run a script file remotely using SSH

I want to run a script remotely. But the system doesn't recognize the path. It complains that "no such file or directory". Am I using it right?
ssh kev#server1 `./test/foo.sh`
You can do:
ssh user#host 'bash -s' < /path/script.sh
Backticks will run the command on the local shell and put the results on the command line. What you're saying is 'execute ./test/foo.sh and then pass the output as if I'd typed it on the commandline here'.
Try the following command, and make sure that thats the path from your home directory on the remote computer to your script.
ssh kev#server1 './test/foo.sh'
Also, the script has to be on the remote computer. What this does is essentially log you into the remote computer with the listed command as your shell. You can't run a local script on a remote computer like this (unless theres some fun trick I don't know).
If you want to execute a local script remotely without saving that script remotely you can do it like this:
cat local_script.sh | ssh user#remotehost 'bash -'
It works like a charm for me.
I do that even from Windows to Linux given that you have MSYS installed on your Windows computer.
I don't know if it's possible to run it just like that.
I usually first copy it with scp and then log in to run it.
scp foo.sh user#host:~
ssh user#host
./foo.sh
I was able to invoke a shell script using this command:
ssh ${serverhost} "./sh/checkScript.ksh"
Of course, checkScript.ksh must exist in the $HOME/sh directory.
Make the script executable by the user "Kev" and then remove the try it running through the command
sh kev#server1 /test/foo.sh