PSEXEC: not recognising remote command - batch-file

I am able to execute basic operation by triggering batch script on remote location using following command.
psexec -e -h -s -u User -p pass \\10.0.0.240 C:\test.bat
But when the test.bat file is calling other program specific script like somepy.py then I am getting error on master batch file that these are not internal command.
Master batch file in Host computer:
CODE
psexec -e -h -s -u user -p pwd \\10.0.0.240 C:\Users\Desktop\TEST\test.bat
Command inside test.batlocated in remote PC:
cd C:\Users\Desktop\TEST1
impact -batch test_impact_warp_AP.cmd
`pause`
waitfor /t 5 StartNow
REM wait for 5second
echo "Run python script for Warp"
cd C:\Users\Desktop
call warp-python.bat
ipconfig /all
ping google.com
Command inside warp-python.bat present in remote machine:
set PYTHONPATH=C:\Users\Desktop\Python_Reference
cd C:\Users\Desktop\Python_Reference\examples\PYTHON_SCRIPT
python t_capture.py
When I executed the test.bat script directly then warp-python.bat as well as test_impact_warp_AP.cmd executes perfectly without any error.
But when i try to execute test.bat from remote location then *python* and *impact* commands are not recognised. and gives following error:
'Impact' is not recognised as an internal or external Command
But ipconfig/all and ping command is executed perfectly in remote PC
What am I missing in the command line argument such that psexec in not able to executed the command in remote location

Add the psexec.exe to your PATH variable in the environment variable or
give the full path of psexec.exe in your command.
Example:
c:\users\test\Desktop\psexec.exe -e -h -s -u User -p pass \10.0.0.240 C:\test.bat
Make sure C:\test.bat is present in your remote machine.

Related

how to run one command to multiple servers with plink in batch

so far what I have is
plink -batch root#1.1.1.1 -pw password COMMAND & plink -batch root#1.1.1.1 -pw password COMMAND
the problem is after the first command starts the batch waits for a response from the server to stop the session and go to the next command, I cant seem to find a way to get around this, I'm looking to have it send the command and immediately start the next command on the next server
You can have the server itself execute the command in the background. So you can use the same techniques as with OpenSSH ssh, as you will be using server-side functionality, unrelated to the local SSH client you are using:
Getting ssh to execute a command in the background on target machine
So something like this:
plink -batch root#1.1.1.1 -pw password "nohup COMMAND > foo.out 2> foo.err < /dev/null &"
Or use local techniques to execute the command asynchronously:
Running Windows batch file commands asynchronously
So something like this:
start "title" /b plink -batch root#1.1.1.1 -pw password COMMAND

Running a HTA file remotely using PSTools

Its almost certain that HTA files are obsolete, but i've found that they are much better than net send / msg.
I'm trying to run a HTA file on a remote machine using PSTools, but instead of it running, it brings back a broken window:
Running the HTA file using CMD (locally) works perfectly though.
My PsExec line:
PsExec.exe -accepteula -i -d \\itwall cmd 'mstha \\intranet\Downloads\VisitorSystemNewMessage.hta asd'
I even tried to run the HTA from a Batch file, but the exact same thing happens.
Any ideas?
It's because the account running the command cannot interact with the session of the remote user.
Use the -s switch to run the HTA using the system account of the remote computer.
Also, you shouldn't need to run cmd. You should be able to just specify mshta.exe then your arguments.
PsExec.exe -accepteula -s -i -d \\itwall mshta.exe \\intranet\Downloads\VisitorSystemNewMessage.hta asd
Edit: To illustrate that this is not an HTA issue. Run the following command:
PsExec.exe -accepteula -i -d \\itwall notepad.exe
Notice you'll have the same black window showing.

Display Batch file output message in local machine

I am using psexec tool to run a batch file in remote machine. Everything is good except that I am unable to see any batch output messages that we usually see in cmd window. I want these msgs on my local machine psexec shell window. Is there anyway to do that?
I am using the command as:
psexec -u admin -p tool#321 \\10.189.21.19 -s -d cmd.exe /c "C:\TEMP\output\batch_script.bat"
What about creating an admin share and outputting the data there?
psexec -u admin -p tool#321 \10.189.21.19 -s -d cmd.exe /c "C:\TEMP\output\batch_script.bat >\\server\logs$\10.189.21.19.txt"

Open SSH tunnel via Plink and run R Scripts via command line batch file

I am trying to open an SSH tunnel via Plink in the command line to run a few R scripts and I cannot get the R scripts to run and when they do run the tunnel was not created, so the connection to my database crashes.
The Plink code looks like this:
plink.exe -ssh [username]#[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
Followed by the code to run the R scripts
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
I cannot seem to get the tunnel to stay open to run the R script. However, I can open the tunnel separately and run the code.
I assume you have the two commands in a batch-file one after another like:
plink.exe -ssh [username]#[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
Then indeed the R.exe is never executed as the plink.exe runs indefinitely.
You have to run the commands in parallel:
You can use start command to run plink.exe in the background.
Use killtask command to kill the background plink process after the R.exe finishes.
You should probably also pause a little before you run R.exe to allow the Plink to establish the tunnel.
rem Open tunnel in the background
start plink.exe -ssh [username]#[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
rem Wait a second to let Plink establish the tunnel
timeout /t 1
rem Run the task using the tunnel
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
rem Kill the tunnel
taskkill /im plink.exe

Psexec to execute batch file,which calls a vbscript,and this vbscript executes test case using qtp on a remote machine

Scenario :
System 1(Remote Machine) :
"abc.bat"
"xyz.vbs"
Both the files are in D Drive
Scenario : "abc.bat" calls "xyz.vbs" and the command is like this: cscript D:\xyz.vbs
"xyz.vbs has script which calls QTP and executes the test script on QTP.
System 2(My Machine) :
I have downloaded PSTools and making use of Psexec command to execute batch file on above remote machine.
In my cmd i have this command.
C:\Program Files\PSTools>psexec -i \System_1's_IP_address -u domain\username -p password D:\abc.bat
When i run this command on my machine, it starts PSexec on remote machine. But QTP is not invoked on the remote machine so execution halts here.
I have checked in task manager.it shows wscript,psexec.
But not QTPro.exe
Is there a solution??
Can somebody please help.
PSEXEC \\<Targetsystem> -u domain\username -p password -i -w D: cmd.exe /c abc.bat
or
place the abc.bat in the same folder as psexec and execute this one:
PSEXEC \\<Targetsystem> -u domain\username -p password -i -c -f abc.bat
(P.S.: a look at PSEXEC /? may help ;))

Resources