Announcement

Collapse
No announcement yet.

Startup Type batch file.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Startup Type batch file.

    Hey all I'm new here but after reading some up on the forums and the main site hopefully will be able to contribute soon. And like the wealth of knowledge I've found. But now to my problem.

    I've been tasked with creating a batch file that after a server's scheduled reboot we get an email about any services that didn't auto start.

    It seems easy upfront but from what I've determined the script will need to go through and find all the automatic startup type's and find out which ones didn't start then send an email to our DL.

    I have so far been unsuccessfull in finding any script or command to even find out the startup type; " psservice" doesn't list an option for startup type and I ran a "reg query" on the services control set and couldn't figure out a way to get it to display the startup type either. Then even if I can somehow compile this information of failed services I need it to email our group. So far I tried postie and Sendmail and neither one seem to be able to sync up to our Exchange server. I get connection errors.

    Any advice or help would be greatly appreciated.

    Code:
    psservice query messenger | find "STATE" | find "RUNNING" > nul && c:\utils\sendmail /smtpserver servername/smtpport port  /to [email protected] /from [email protected] /subject Message subject /body message body
    this is the only code I have so far and obviously this is only running a query on 1 service not all the services.
    Last edited by Gryz; 2nd April 2008, 12:25.

  • #2
    Re: Startup Type batch file.

    Do you need to use a batch file?

    Here's something I whipped up in VBS:
    Code:
    strComputer = "."
    
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colAutoStSvc = objWMIService.ExecQuery("SELECT * FROM Win32_Service " _
                                              & "WHERE StartMode = 'Auto'")
    
    For Each objService in colAutoStSvc
      If NOT objService.State = "Running" Then
        Wscript.Echo "The " & objService.DisplayName & " is in the " & _
                      objService.State & " state."
      End If
    Next
    Obviously this only echoes them but I don't know off the top of my head the code for emailing. If I get time I might be able to write/find that.
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Startup Type batch file.

      I'll have to try that out. It doesn't need to be a batch perse it just needs to be automated since for some reason everyone in our environment thinks their servers need to be on a nightly reboot schedule

      I have to admit a little ignorance here can VBScripts be run along with scheduled tasks after a server comes back online?

      Now that I'm thinking about this even further it would probably have to be run by one of us int he Ops Center client side it's going to do no good to even put a script like this on a server that may or may not come back online after a reboot. We'd never get an email failure notice and just assume the reboot went off without a hitch.

      So that means the email side of things is irrelevant and I think your script will work as is

      Comment


      • #4
        Re: Startup Type batch file.

        The answer is yes, it can be run as a Scheduled task.

        What you could do is have it run as a startup script and put a delay of 10 or 15 mins (to let everything get settled) and have it email regardless of whether there's auto start services not running. It could be an alert saying the server rebooted.

        Just a thought.
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment


        • #5
          Re: Startup Type batch file.

          I thought about that too but we have a pretty big list of servers we are monitoring. Given that we get about 200 emails a day I don't know how happy people are going to be getting "everything is working fine" emails

          Technically speaking if the server doesn't come back online NetIQ or MOM should pick it up as a ping fail.

          I think you have given me a huge point of attack and I feel like I'm much further along with at least being able to check services automatically after a server reboots.

          Thanks alot for the great info

          Comment


          • #6
            Re: Startup Type batch file.

            Glad to help.

            BTW - I've never used MOM before but I thought it would be able to monitor services on servers... have you looked into using MOM for this?
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment


            • #7
              Re: Startup Type batch file.

              Jeremy you are awesome! This script worked out better than I could have imagined. Right now I'm working on getting the email portion setup but I thought I'd share with you how I'm using the script currently.

              I made a script that asks the user for a server name and saved your original script for running directly on the server as a scheduled task. Here's the adjustments I made to ask for user input:

              Code:
              strUserIn = InputBox("Please Enter the Server Name") 
              Set fs = CreateObject("Scripting.FileSystemObject") 
              strFileName = fs.BuildPath(Wscript.ScriptFullName & "\..", "~userin.bat") 
              strFileName = fs.GetAbsolutePathName(strFileName) 
              Set ts = fs.OpenTextFile(strFileName, 2, True) 
              ts.WriteLine "set userin=" & strUserIn 
              ts.Close 
              
              strComputer = "."
              strComputer = strUserIn
              
              Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
              Set colAutoStSvc = objWMIService.ExecQuery("SELECT * FROM Win32_Service " _
                                                        & "WHERE StartMode = 'Auto'")
              
              For Each objService in colAutoStSvc
                If NOT objService.State = "Running" Then
                  Wscript.Echo "The " & objService.DisplayName & " is in the " & _
                                objService.State & " state."
              	
                End If
              Next
              Then the Batch file I made (I made 2 one to display in the CMD window) generates a .txt report, which I'll figure out how to email later.

              Code:
              @ECHO off
              del report.txt
              ECHO. REPORT DATE >> report.txt
              ECHO. %DATE% >> report.txt
              ECHO. REPORT TIME >> report.txt
              ECHO. %TIME% >> report.txt
              ECHO. >> report.txt
              
              ECHO _______________________________________________________________________ >> report.txt
              ECHO The following services are set to automatic but are not running:  >> report.txt
              ECHO.>> report.txt
              cscript checkservicesuserin.vbs //nologo >> report.txt
              call ~userin.bat 
              del ~userin.bat  
              ECHO. >> report.txt
              echo The above services are not running on: %USERIN% >> report.txt
              ECHO _______________________________________________________________________ >> report.txt
              ECHO. >> report.txt
              ECHO. >> report.txt
              
              ECHO ################################################################# >> report.txt
              ECHO        Uptime Report:  >> report.txt
              ECHO.>> report.txt
              uptime %USERIN% >> report.txt
              ECHO.>> report.txt
              ECHO ################################################################# >> report.txt
              
              ECHO.>> report.txt
              ECHO.>> report.txt
              ECHO __________________________________________________>> report.txt
              ECHO  If Terminal Services are running RDP is ENABLED>> report.txt
              ECHO. >> report.txt
              psservice \\%USERIN% query Terminal |find "SERVICE_NAME:" >> report.txt
              psservice \\%USERIN% query Terminal |find /n "STATE" >> report.txt
              ECHO __________________________________________________>> report.txt
              start notepad report.txt
              Thanks again for all your help!
              Yup I've looked into MOM for it but I only have view rights to it and our Monitoring team makes the adjustments. Our monitoring team is pretty pathetic though, understaffed and underqualified. So the chances of seeing any changes like this are going to be nearly impossible since they just rolled out MOM about 2 months ago and they haven't even been able to get it working yet. (I created a script just to close and open it because it freezes up when we close it and wont auto refresh).

              I think NetIQ can do some service monitoring too but once again our EMS team doesn't have anyone fully trained in it.
              Last edited by Gryz; 3rd April 2008, 04:48. Reason: UPDATE

              Comment

              Working...
              X