어떻게 검출하는 경우 윈도우 서버가 사용할 수 있 후 재부팅?

StackOverflow https://stackoverflow.com/questions/56644

  •  09-06-2019
  •  | 
  •  

문제

내가 원하는 자동화하는 윈도우 2000+서버를 재부팅 프로세스를 사용하여 작업 스케줄러 또는 유사한 도구를 원격으로 재부팅이 서버를 다시 올니다.내가 할 수 있습 문제 shutdownpsshutdown 을 원격으로 재부팅이지만,내가 뭔가를 원하는 보다 더 sleep 을 기다리는 돌아오.내가 필요로하는지 확인합니다 온라인으로 다시 내에서 n 분거나 오류가 있습니다.

에 의해'다시 온라인',나는 것과 같은지 확인하보다 더 될 수 있다는 ping 지만,아마도 그것은 RFC 서비스가 응답하지 않거나 일부 다른 확정된 중요한 표시입니다.

아보 NT 접근 방식은 스크립트,하지만 나 지배 쓰기 사용자 지정 도구를 하겠다.

어떤 아이디어가?

도움이 되었습니까?

해결책

원격을 다시 시작 스크립트는 서버를 시작,기 n 분,그리 RFC 서비스입니다.당신은 또한 지역 스크립트는 서버에서 동일한 것입니다.

다른 팁

후에는 작업에 대한하는 동안,나는 다음과 같은 VBScript.한 의견 주시기 바랍니다/니다.

'
' Remotely reboot a server and
' wait for server to come back up.
'
' Usage:  cscript /nologo /E:VBScript RebootWait.vbs <Server Name>
'
' Shawn Poulson, 2008.09.11
'

'
' Get server name from command line
'
If WScript.Arguments.Count <> 1 Then
   ShowUsage()
   WScript.Quit(1)
End If

ServerName = WScript.Arguments(0)

'
' Verify server is currently up
'
WScript.StdOut.WriteLine Now & ": Verify server '" & ServerName & "' is currently up..."
If Not IsAvailable(ServerName) Then
   WScript.StdOut.WriteLine "Error: Server is down.  Reboot aborted!"
   WScript.Quit(1)
End If
WScript.StdOut.WriteLine Now & ": Server is up."

'
' Reboot server
'
WScript.StdOut.WriteLine Now & ": Rebooting server '" & ServerName & "'..."
RebootStatus = RebootServer(ServerName)
If RebootStatus < 0 Then
   WScript.StdOut.WriteLine "Error: Reboot returned error " & RebootStatus
   WScript.Quit(1)
End If
WScript.StdOut.WriteLine Now & ": Reboot command was successful"

'
' Wait for server to come down
'
WScript.StdOut.Write Now & ": Waiting for server '" & ServerName & "' to go down..."
WaitCount = 0
Do While IsAvailable(ServerName)
   WaitCount = WaitCount + 1
   If WaitCount > 60 Then ' 5 min timeout
      WScript.StdOut.WriteLine "Error: Timeout waiting for server to come down!"
      WScript.Quit(1)
   End If
   WScript.StdOut.Write(".")
   WScript.Sleep(5000)
Loop
WScript.StdOut.WriteLine "Success!"
WScript.StdOut.WriteLine Now & ": Server is down."

'
' Wait for server to come back up
'
WScript.StdOut.Write Now & ": Waiting for server '" & ServerName & "' to come back up..."
WaitCount = 0
Do While Not IsAvailable(ServerName)
   WaitCount = WaitCount + 1
   If WaitCount > 240 Then ' 20 min timeout
      WScript.StdOut.WriteLine "Error: Timeout waiting for server to come back up!"
      WScript.Quit(1)
   End If
   WScript.StdOut.Write(".")
   WScript.Sleep(5000)
Loop
WScript.StdOut.WriteLine "Success!"
WScript.StdOut.WriteLine Now & ": Server is back up after reboot."

'
' Success!
'
WScript.Quit(0)


Sub ShowUsage()
   WScript.Echo "Usage: " & WScript.ScriptName & " <Server name>"
End Sub

' Returns:
' 1 = Successfully issued reboot command
' -2 = Could not reach server
' -3 = Reboot command failed
Function RebootServer(ServerName)
   Dim OpSystem
   On Error Resume Next
   For Each OpSystem in GetObject("winmgmts:{(Shutdown)}!\\" & ServerName & "\root\CIMV2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
      On Error GoTo 0

      If IsObject(OpSystem) Then
         ' Invoke forced reboot
         If OpSystem.Win32Shutdown(6, 0) = 0 Then
            ' Success
            RebootServer = 1
         Else
            ' Command failed
            RebootServer = -3
         End If

      Else
         RebootServer = -2

      End If
   Next
End Function

' Return True if available
Function IsAvailable(ServerName)
   ' Use Windows RPC service state as vital sign
   IsAvailable = (GetServiceState(ServerName, "RpcSs") = "Running")
End Function

' Return one of:
'  Stopped, Start Pending, Stop Pending,
'  Running, Continue Pending, Pause Pending,
'  Paused, Unknown
Function GetServiceState(ServerName, ServiceName)
   Dim Service
   On Error Resume Next
   Set Service = GetObject("winmgmts:\\" & ServerName & "\root\CIMV2:Win32_Service='" & ServiceName & "'")
   On Error GoTo 0
   If IsObject(Service) Then GetServiceState = Service.State
End Function

당신이 사용할 수 psservice 의 상태를 쿼리 RFC 또는 인쇄 스풀러 서비스입니다.스풀러에 일반적으로 하나의 마지막 서비스를 시작합니다.당신이 사용할 수 있는 구문을 다음과 같:

psservice \\someothermachine query spooler

을 반환하는 무언가 다음과 같이면 서비스가 실행되고 있습니다.

SERVICE_NAME: Spooler                                                                             
DISPLAY_NAME: Print Spooler                                                                       
Manages all local and network print queues and controls all printing jobs. If this service is stop
ped, printing on the local machine will be unavailable. If this service is disabled, any services 
that explicitly depend on it will fail to start.                                                  
        GROUP             : SpoolerGroup                                                          
        TYPE              : 110 WIN32_OWN_PROCESS INTERACTIVE_PROCESS                             
        STATE             : 4  RUNNING                                                            
                               (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)                          
        WIN32_EXIT_CODE   : 0  (0x0)                                                              
        SERVICE_EXIT_CODE : 0  (0x0)                                                              
        CHECKPOINT        : 0x0                                                                   
        WAIT_HINT         : 0x0                                                                   

는 경우 다른 컴퓨터가 준비되지 않은,당신은 다음과 같은 결과를 얻

Unable to connect to \\someothermachine:                                                                  
The RPC server is unavailable. 

VBScript(WSH)당신은 그것을 확인할 수 있다.상태 제공합니다.이 스크립트 보여주는 객실에서 사용되는 다른 응용 프로그램만 설명하는 데 도움이디:

http://www.robvanderwoude.com/vbstech_proc_service.html

nmap 의 목록을 얻으려면 오픈 서비스는 기계 분석 결과를 확인 할 필요가 무엇이 활성화됩니다.그것은 또한 유용한지 확인하는 것을 당신 필요 active.

설문조사를 시행할 수 있습 몇 가지 핵심 서비스를 볼 시작된 경우:

sc "\\server_name" query EventSystem

여기에 열쇠가 필요하는 스크립트이다.가 깨끗한 방법으로 추출하는 서비스 상태에서 psservice/sc query?할 수 있어요 그것에 관하여 findstr "RUNNING", 하지만 거기에 있을 더 나은 방법입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top