M
MordacNM
The following script appears to work per your request -
The results are as they should be.
HTH
Dean
Still no joy on this - I tried both alternatives posted (by Dean and
Ritchie)...
Here's the actual batch file I'm working on. Maybe more details will help.
The batch is running a sql query into a file called masterlist.txt. Then
use another findstr command to filter out some machine prefixes (line 20).
and redirect the results of this into machines.txt. Set variable
date1/time1 and use these to record activity (machine count) into
ActivityLog.txt. I want to remove any machines (exclude.txt) from
machines.txt and use these names and run another batch (go.cmd) that uses
PSService restart to restart the service on the machines. I run into
several machines that don't respond to the PSService restart function (they
hang) and thus the PSKill at the end gets rid of these extraneous cmd
windows.
Still cannot get the machine names contained in exclude.txt to NOT be
listed in the machines.txt file that the rest of the batch works off of.
Still puzzled...
1. @ECHO OFF
2. @COLOR 1F
3. @TITLE ITA Re-Start
4.
5. :TOP
6.
7. SETLOCAL
8. CALL :CREATE
9. CALL :SERVTEST
10. CALL :LOOP
11. ENDLOCAL
12.
13. GOTO :EOF
14. :CREATE
15. del masterlist.txt>nul
16. del machines.txt>nul
17. cls
18.
19. isql -S sqlservername -d sqltablename -E -h-1 -Q "SELECT MachineName
FROM vwSQLServerView WHERE LastHelloOn > DATEADD(day, -1,
CURRENT_TIMESTAMP) " -o masterlist.txt
20. findstr /l /i /v "( cre- fitl- ncsc- upds- b- icsc- itl- aserver
dccs50" masterlist.txt > machines.txt
21. FOR /f "tokens=2,3,4 delims=/ " %%I in ('DATE /T') DO (SET date1=%%I-%%
J-%%K)
22. FOR /f "tokens=1,2 delims=:" %%T in ('TIME /T') DO (SET time1=%%T:%%U)
23. FOR /f %%a in ('find /v /c "" ^< machines.txt') DO (SET linecount=%%a)
24. echo %date1% %time1% COUNT = %linecount%>>c:\killita\ActivityLog.txt
25. GOTO :EOF
26.
27.:SERVTEST
28. FOR /F "tokens=1 eol=(" %%I in (
'findstr /b /l /i /v /g:exclude.txt c:\killita\machines.txt') DO (
SET Machine=%%I) & (CALL INGIT)
29. GOTO :EOF
30.INGIT
31. ping -w 2000 -n 1 %MACHINE% | find " TTL=">nul
32. IF NOT ERRORLEVEL 1 (GOTO :RESTARTSERVICE)
33.
34. :BADPING
35. echo %time1% %machine% Unavailable
36. GOTO :ENDSTAT
37.
38. :RESTARTSERVICE
39. FOR /f "tokens=1,2 delims=:" %%I in ('TIME /T') DO (SET time1=%%I:%%J)
ECHO %time1% %MACHINE%
40. start /min go.cmd
41. GOTO :ENDSTAT
42.
43. :LOOP
44. sleep 30
45. pskill psservice.exe>nul
46. GOTO :TOP
47.
48. :ENDSTAT
49.
50. GOTO :EOF