Page 1 of 1

PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 30 Jul 2016 10:07
by SIMMS7400
HI Guys -

Would there be a reason why when executing a PSEXEC script on my source server, it fails on the XCOPY portion of a script it executes on the target server?

Source server syntax:

Code: Select all

echo ********************************************************>>%logfiles%
echo LOAD starts at %TIME%                     >>%logfiles%
echo ********************************************************>>%logfiles%
echo Executing PSExec...

SET HYPPLAN_FCST_SCRIPT=Process_HypPlan_Fcst_ENHANCEMENT.cmd

%MAINPATH%%PSToolsPATH%PSexec.exe %ESS_SERVER% %HFM_EXTRACT_PATH%%HYPPLAN_FCST_SCRIPT% -u %PSUSer% -p %PSPass% -w %HFM_EXTRACT_PATH% /accepteula>>%logfiles%



Portion of code in the target server script it fails on:

Code: Select all

ECHO ***************************************************************
ECHO COPY DATA FILE ON %ESS_SERVER% TO %FDMEE_SERVER% AND RENAME
ECHO ***************************************************************
ECHO.

ECHO f | XCOPY /f /y "%HFM_EXTRACT_PATH%HypPlan_Fcst.txt" "%FDMEE_SERVER%\F$\FDMEE_PROJ\inbox\HypPlan_Fcst.txt">>%logfile%


The error I get fromt he source script is:

Invalid drive specification.
The syntax of the command is incorrect.


However, if I execute the remote script manually, it runs with success. Scratching my head here. I've tried the regular COPY command and I get an "access denied error" but again, if I execute the target script manually even with the COPY command it finishes fine.

Also, all piece of code PRIOR to this XCOPY portion execute fine. It's just this piece.

Any ideas?

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 30 Jul 2016 13:42
by SIMMS7400
I've done more testing and the process works if no variables are used. FO rinstance, in place of the current XCOPY portion of code in the remote server script, I used:

Code: Select all

ECHO f | XCOPY /f /y "TEST.txt" "TESTFINAL.txt">>%logfile%


And that works. However, when I add a variable to the SOURCE path, it fails and says file cannot be found. BUT, if I add a variable to the target path, it works fine.

But when I add the remote server path as follows:

Code: Select all

ECHO f | XCOPY /f /y "TEST.txt" "\\dtvcrphypapp02\F$\FDMEE_PROJ\inbox\TEST.txt">>%logfile%


It fails and says
Invalid drive specification


So two things are happening:

1. Its doesn't know how to read variables in source paths
2. Unable to copy remotely.

THe service account I'm use has sufficient privileges.

Please note, I am calling an environment file in both scripts to set the variables.

Any ideas?

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 30 Jul 2016 16:04
by SIMMS7400
Hi Guys -

One last update.

Variable in the target script in source paths, for instance, any MOVE or COPY commands, are still unable to be read. However, I"ve removed those variables and used the hard coded paths. I'm also able to copy to remote servers from the target script now.

I changed the source PSEXEC syntax to the following:

Code: Select all

echo ********************************************************>>%logfiles%
echo LOAD starts at %TIME%                     >>%logfiles%
echo ********************************************************>>%logfiles%
echo Executing PSExec...

SET HFM_EXTRACT_PATH=F:\Batch_Process\Hyperion_Planning\Production\IncStmt\HFM_Extract\
SET HYPPLAN_FCST_SCRIPT=Process_HypPlan_Fcst_ENHANCEMENT.cmd

%MAINPATH%%PSToolsPATH%PSexec.exe %ESS_SERVER%.clientname.com -u %PSUSer% -p %PSPass% cmd /c %HFM_EXTRACT_PATH%%HYPPLAN_FCST_SCRIPT%


Now, the previous issues have been resolved, but a new one has transpired.

On the target server script, I get the following error when it encounters this portion of code:

Code: Select all

ECHO **********************************************
ECHO EXECUTE FDMEE BATCH SCRIPT ON %FDMEE_SERVER%
ECHO **********************************************
ECHO.

CALL cmd /C F:\Hyperion_Batch\Scripts\batch\psExecScript_FDMEE.cmd REFG_to_HFM_Fcst.bat


The error is as follows:

the process tried to write to a nonexistent pipe


psExecScript_FDMEE.cmd is a batch script that contains another PSEXEC command and REFG_to_HFM_Fcst.bat is passed in as a parameter.

The weird thing is, even with that error, the batch script continues executing and all remaining sections run without error.

I've been googling this code and there really isn't much info on it. Has anyone else ever experienced this?

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 31 Jul 2016 06:53
by SIMMS7400
Hi Guys -

One more update. Been testing a bunch of different things.

I'm back to square one. The previous fix yesterday was not an actually fix. I was mistaken.

A few things are still going on:

1. Unable to read any variables in remote batch file I'm trying to execute
A. The remote batch file calls it's own environment file. Does PSEXEC not have the ability to read that into memory?
2. Still getting the following error when it gets tot he portion of code int he remote script that is inclusive of another PSEXEC process:
the process tried to write to a nonexistent pipe


Thanks!

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 31 Jul 2016 07:55
by aGerman
I never used PSEXEC. Only some thoughts
1. Unable to read any variables in remote batch file I'm trying to execute

Environment variables are inherited from the parent process. Try to determine what it is.
Something like that should help you ...

Code: Select all

@echo off &setlocal DisableDelayedExpansion
set "myName=%~nx0"
set "pPID="
set "pName="

setlocal EnableDelayedExpansion
for /f "skip=1" %%i in (
  'WMIC PATH Win32_Process WHERE "Name='cmd.exe' AND CommandLine LIKE '%%!myName!%%' AND NOT CommandLine LIKE '%%WMIC PATH Win32_Process WHERE%%'" GET ParentProcessId'
) do if not defined pPID set /a "pPID=%%i" 2>nul
if not defined pPID (
  echo CMD Prompt Supposed
) else (
  for /f "skip=1 delims=" %%i in (
    'WMIC PATH Win32_Process WHERE "ProcessID='%pPID%'" GET Name 2^>nul^|findstr .'
  ) do if not defined pName set "pName=%%i"
  if defined pName (
    echo Parent Process Name: !pName!
  ) else (
    echo Parent Process Was Already Terminated.
  )
)


A. The remote batch file calls it's own environment file. Does PSEXEC not have the ability to read that into memory?

Where is the environment file placed? Did you use a relative path? What's the working directory? (Maybe you have to adjust it using cd /d "%~dp0")

Regards
aGerman

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 01 Aug 2016 04:50
by SIMMS7400
HI aGerman -

So, a quick update, I've been able to get my remote batch script to execute. What I needed to do was declare all variables in the script itself, rather than in an environment/properties file I call from it.

While it works, it of course is a little cluttered.

For instance, this is how I was calling my properties file in my remote script:


Code: Select all

REM -- Call Environment File 

CALL _env.cmd

REM --Set working directory as script path--
cd /d %~dp0


As you can see, nothing out of the ordinary. Do you have any idea why the psexec process wont read this file called from my remote script? _env.cmd and the remote script are in the same directory/folder.

Thanks!

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 01 Aug 2016 05:59
by aGerman
You changed the working directory after you called _env.cmd. Why? In case the original working directory was not the script path then it will fail to find the file.
FWIW I read in the internet that PSEXEC provides an option to set the workdir. -w as far as I remember.

Regards
aGerman

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 01 Aug 2016 06:27
by SIMMS7400
Hi aGerman -

_env.cmd sits in the working directory. Perhaps it's unnecessary?

I did try the working directory syntax but unfortunately, its still unable to read that _env file on the remote server.

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 01 Aug 2016 08:20
by aGerman
_env.cmd sits in the working directory.

How can you be sure?

Code: Select all

REM --Set working directory as script path--
cd /d %~dp0

REM -- Call Environment File
CALL _env.cmd

If your _env.cmd ist placed in the script path it should work now. (At least I hope that %0 behaves as in a local process.)

Regards
aGerman

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 01 Aug 2016 13:50
by aGerman
OK, I downloaded PSEXEC and did a test.

C:\test\local.bat

Code: Select all

@echo off &setlocal
psexec \\%COMPUTERNAME% cmd /c "D:\remote.bat"
pause



C:\test\local_env.bat

Code: Select all

set "test1=local_test"



D:\remote.bat

Code: Select all

@echo off &setlocal

echo %cd%
call "local_env.bat"
echo "%test1%"

cd /d "%~dp0"
echo %cd%
call "remote_env.bat"
echo "%test2%"

pause



D:\remote_env.bat

Code: Select all

set "test2=remote_test"



PSEXEC is in C:\test too. Running "C:\test\local.bat".

remote.bat Window:

Code: Select all

C:\test
"local_test"
D:\
"remote_test"
Drücken Sie eine beliebige Taste . . .



local.bat Window:

Code: Select all

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

cmd exited with error code 0.
Drücken Sie eine beliebige Taste . . .


As you can see everything works as expected (even if both "local" and "remote" was eventually the same computer).

Regards
aGerman

Re: PSEXEC script claims XCOPY syntax invalid on remote server

Posted: 03 Aug 2016 18:03
by SIMMS7400
aGerman -

Thank you so much for all your efforts! This makes sense and I have been able to get my process to execute.

Thank you!