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

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. :)

Related

Running sqlplus inside cmd.exe using sshexec

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"'/>

Getting error in SQL Server executing get-wmiobject

I am trying to execute following PowerShell query in SQL Server
xp_cmdshell "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"
After executing this, I am getting error:
'get-WmiObject' is not recognized as an internal or external command,
operable program or batch file.
I want to execute this command in all SQL Servers. It's getting executed on SQL Server 2008, but on SQL Server 2012, it's throwing that error due to version or some PowerShell component is not installed.
Can you to please look at the code and let me know
Try:
xp_cmdshell 'PowerShell.exe -noprofile -command "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"'
If this doesn't work logon to the server open PowerShell with administrator rights. Type Get-ExecutionPolicy and check that Execution Policy is set to Unrestricted. If it isn't then enter the following, then type 'A' (Yes to All):
Set-ExecutionPolicy Unrestricted
If this still doesn't work try upgrading to at least PowerShell V3. But if this is not possible you can try repair your corrupt PowerShell V2 WMI repository with:
winmgmt /verifyrepository
If repository is found to be inconsistent run Winmgmt /salvagerepository and Winmgmt /resetrepository and verify after each. If it is still inconsistent try the following steps:
Go to Task Manager>> Services >> Open Service >> Windows Management Instrumentation service, and change the start up type to Manual.
Stop the WMI service:
net stop winmgmt
Rename the repository folder (C:\Windows\System32\wbem\Repository) to some else 'Repository_OLD'.
Start the WMI service:
net start winmgmt
Set the service back to auto start.
Failing Re-register all of the dlls and recompile the .mofs in the Wbem directory with the following .bat script and then reboot.
#echo off
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in (‘dir /b *.dll’) do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %%s in (‘dir /s /b *.mof *.mfl’) do mofcomp %%s

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.

Cannot execute commands on Windows server over SSH session with Plink

I am trying to use Plink for running commands on remote server. Both, local & remote machine are Windows. Though I am able to connect to the remote machine using Plink, i am not able to use the '-m file' option. I tried the following three ways but to no avail:
Try 1:
plink.exe -ssh -pw mypwd john.doe#server -m file.txt
Output:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
'file.txt' only contains one command i.e., dir
Try 2:
plink.exe -ssh -pw mypwd john.doe#server dir
Output:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
Try 3:
plink.exe -ssh -pw mypwd john.doe#server < file.txt
In this case, I get the following output:
Using username "john.doe".
****USAGE WARNING****
This is a private computer system. This computer system, including all
..... including personal information, placed or sent over this system
may be monitored.
Use of this computer system, authorized or unauthorized, constitutes consent
... constitutes consent to monitoring for these purposes.
dirCould not chdir to home directory /home/john.doe: No such file or directory
Microsoft Windows [Version x.x.xxx]
(C) Copyright 1985-2003 Microsoft Corp.
C:\Program Files\OpenSSH>
After I get the above prompt, it hangs. Any help in this regard?
It seems like plink -m is working fine: the commands from file.txt are being sent to the server.
However, your SSH server is running a shell (probably bash because OpenSSH for Windows uses Cygwin) that does not understand the commands you are using, like move and dir. Because bash implements its own versions of those commands (mv and ls, respectively). As you discovered, you need to run cmd.exe /C out of the Windows directory for your SSH server to correctly interpret the meaning of your commands. The other option is to use the bash versions of the commands directly.
This is working now.
plink -ssh -pw xxx john.doe#server cmd.exe /c move c://sample//jd//file.txt c://test//
You are using OpenSSH over Cygwin on your Windows server.
The Cygwin emulates Unix environment on Windows.
So you have to use Unix, not Windows commands (e.g. mv not move or rename)
And you need to use Unix-like paths, not Windows paths (forward slashes in particular).
Moreover, your server seems wrongly configured.
Could not chdir to home directory /home/john.doe: No such file or directory
This is likely an incorrectly configured account. The error is not related to the commands you are executing.