0
@echo off
:begin
for /f %%a in (computerlist.txt) do (
  setlocal
  psexec \\%%a -u user -p password -i -d "d:\path\command.exe"
  endlocal
)

when the script is running, when it finds a machine to be unreachable I want it to skip it.

How do i write the script to skip an unreachable computer and continue to the next one in the txt file?

Dale
  • 1,903
  • 1
  • 16
  • 24
Dre_Dre
  • 745
  • 2
  • 6
  • 15
  • For what it's worth, if you don't care about the output of the command you're executing via `psexec`, then `wmic /node:%%a /user:user /password:password process call create "cmd /c \"d:\\path\\command.exe\""` will work faster than `psexec`. – rojo Feb 13 '13 at 01:49

2 Answers2

0

How about a simple test to see whether a machine is pingable?

@echo off
setlocal
:begin
for /f %%a in (computerlist.txt) do (
    ping -n 1 %%a >NUL 2>NUL
    if %errorlevel%==0 (
        psexec \\%%a -u user -p password -i -d "d:\path\command.exe"
    ) else echo Skipping unreachable host %%a
)
endlocal
rojo
  • 24,000
  • 5
  • 55
  • 101
0

Actually, windows ping.exe doesn't return meaningful errorlevels, (huh?)
It ALWAYS returns a "0" errorlevel, unless the IP-Protocol stack itself is hosed.

WHAT YOU HAVE TO DO IS: pipe the output of your ping to a txt-file, and "find" for TTL=
ie

ping 10.10.10.10. >pingtest.txt
findstr /C:"TTL=" pingtest.txt >nul
if %ERRORLEVEL% equ 0 (do whatever) else (echo skipping unreachable host "whatever")

Then use Find.exe or Findstr.exe to look for TTL= in your output file
(note find, and findstr both use "0" errorlevel when they "find" what your searched on)
1. Ping can fail for a whole lot of reasons, but "TTL=" is always part of a successful ping
2. I always ping at least -n 3 times, because occasionally the first one or two might have problems, and I want to give it more possible chances to succeed before I skip it.
3. For this to work, you have to use the FOR loop method above, just raw psexec.exe has not current means to test/skip targets called from a text file.
4. If you need to use network resource in your psexec session then you need to run the "-h" option so that you get the elevated token, which allows you to map drives

I HOPE THIS HELPS !

Zip Zinzel
  • 69
  • 1
  • 3