PsExec and Invalid Descriptors

I am trying to use a windows script package that uses PsExec to execute commands on a remote machine. Periodically, it has an "invalid descriptor", and the script fails.

the script has not changed or was not a machine at all.

Does anyone know why this happens, how sometimes scripts work without crashing.

Also, does anyone know how to run a script on a machine as a local user for this machine with more reliable technology.

PS Sometimes the first PsExec works, and the rest fail.

EDIT

the script is online (except for the given variables)

  PsExec %HOSTNAME% -I -u %USERNAME% -p %PASSWORD% CMD /C RMDIR /S /Q e:\SomeDir 

This sometimes works, but sometimes with an "invalid descriptor" error

+6
source share
3 answers

You need to debug the situation.

You have a script, then something (what is Jenkins?) Runs it on a remote PC, once it works, once it fails.

Is it deterministic? When he fails, does it always fail?
How does this happen?

You need to get a better idea of ​​how / if the script fails.

Here is what I would like to do to better understand that this fails.

Can you run the script several times?
From the comments it seems that you run the script every hour, can you run it 3/4/5 times in a row, for every hour?
This will help you determine how this will happen: if you run it 5 times, does it work every time? Does he fail, does he fail 5 times in a row?

Is it possible to use different script?
You can create several similar but simpler scenarios.
This way you can try your script using RMDIR, then another script with a simple DIR command (only if the script start / connect mechanism works), and then another script with a simple ECHO command (so it doesent need to be accessed to any files / folder)

Run debug scripts on local PC
Then you can simultaneously run other scripts that run on the LOCAL PC (and not on the remote, where you need to run RMDIR) that try to access the remote PC using PING or by copying the file from / to a network share ...

Take off the net
You can even set up an instance of Wireshark that registers the entire packet sent between two PCs, this can be useful for analyzing / eliminating network problems.

You clearly need to track / record everything.

With this information, perhaps you / we can better understand where the problem is.

=======================================

UPDATE 1 - Record some journal

=======================================

Perhaps you can try using the following modified scripts to have some log files. These scripts will create 2 log files, one on the remote PC (containing the remote command message) and one on the local PC (containing any message from PsExec)

(you will need to configure the path where the log file is saved)

 psexec %HOSTNAME% -I -u %USERNAME% -p %PASSWORD% CMD /C "RMDIR /S /Q e:\SomeDir >>c:\RemoteComputer.log 2>&1" >>c:\LocalComputer.log 2>&1 

or next without / i
Are you sure you need the / I options for CMD? On my PC, this does not work if I use the / I options ...

 psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "RMDIR /S /Q e:\SomeDir >>c:\RemoteComputer.log 2>&1" >>c:\LocalComputer.log 2>&1 

After some tests on my computers, I saw that PsExec installs the service on a remote PC to run the command remotely. (It is called PsExecSvc.exe, installed in c: \ windows \ on the WinXP computer, which I use for this test)
Remotely installing / uninstalling this temporary service to execute a command can certainly be one of the possible “failure points” that generate an error.
If so, then you should be able to track this by looking at LocalComputer.log, which will contain the message / error from PsExec.

As stated in my previous tip, I will also try to schedule a simpler script like

 psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "dir c:\ >>c:\RemoteComputerDir.log 2>&1" >>c:\LocalComputerDir.log 2>&1 

and

 psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "echo SuperEchoTest >>c:\RemoteComputerEcho.log 2>&1" >>c:\LocalComputerEcho.log 2>&1 

=====================================

UPDATE 2 - Try using WMI

=====================================

You can try to run a remote command using WMI

 wmic /node:%HOSTNAME% /user:%USERNAME% /password:%PASSWORD% process call create "CMD /C RMDIR /S /Q e:\SomeDir" 

When using WMI, you must be sure that Windows Firewall is not blocking your command. (when I tried to run the remote command with WMIC, a notification about the Windows firewall appeared on my Win 7 computer)

(I have instructions for using WMIC here )

+3
source

Yes, there is a more reliable technology for executing commands on a remote computer and is called powershell . For example, you can run:

 test-connection -computername server01, server02, server12 

from a local computer to multiple remote computers.

Another very useful command:

 invoke-command -filepath c:\scripts\test.ps1 -computerName Server01 

runs Test.ps1 script on Server01.

A tutorial gives some examples of how to run PowerShell commands on remote computers.

+1
source

You can find another technology that mimics the world of Linux, and using ssh . This is very common with clusters, and I personally used it with Windows Server 2008 R2, so I do not expect any difference in Windows 7.

This task is usually accomplished with ssh public key authentication and without a password. In this case, the only necessary information is the IP of the remote server and the client’s public key stored on the server: only the client with the corresponding private key can connect to it (keys must be created using ssh-keygen , on the client. The public key is copied to the server)

The server must have access to TCP port 22 from the outside, if there are firewalls, NAT, ...

In my case, I used the ssh server included in the Windows SUA , but I suggest you forget them (they are outdated and quite cumbersome actually) and try the OpenSSH cygwin server, sshd - even if it’s not officially Microsoft, there is a large community supporting it as minimum - and sometimes I used it reliably.

The ssh client command is included in SUA, in cygwin, or you can use putty if you want a light solution on the client (not that cygwin is heavy - just the burden of having some kind of Linux emulation that is not needed)

Giving a search, for example, I found this post , well explaining the necessary steps.

0
source

All Articles