' ftp-sys-chk.vbs copyright 2004,2005 orii0 ' check server environment and process for Windows98/NT/2000/2003 ' report to text file and send via FTP ' 05/13/04 orii0 create ' 06/18/04 orii0 add event log for windows 2003 server ' 06/19/04 orii0 separate event log file from text file. ' 06/22/04 orii0 omit normal event. ' 08/17/04 orii0 omit error message(MsgBox) ' 12/08/04 orii0 change max. log files 10 to 24 ' 12/21/04 orii0 add re-schedule function '----------------------- ' CONSTANTS for exection '----------------------- Const PGM_NAME = "ftp-sys-chk" 'Program name myPGM = PGM_NAME & ".vbs" Const PGM_VER = "1.080" 'Varsion TXT_NAME = PGM_NAME & ".txt" 'Report file name EVENTF_NAME = PGM_NAME & "-event.txt" 'Event log file name FTPPARM = PGM_NAME & "-ftpcommand.txt" 'FTP command file name Const FTPSRVR = "192.168.0.20" 'FTP server myUPS = "" myERR = "" myEVENTS = "" myHOSTNAME = "" ' ' Switches for re-schedule of taks ' The processing of the re-schedule is executed at the specified time. ' Const schdSW = "off" ' re-schedule if on Const schdDATE = "2004/12/23" ' submit date of scheduller Const schdTIMES = "08:00" ' start time Const schdTIMEE = "10:00" ' end time ' '============== ' Main routine '============== Call syschk If myERR <> "" Then ' MsgBox("Error:"& myERR ) End If ' re-schedule 'If schdSW = "on" Then ' Call rschedule 'End If '============ ' Subroutine '============ Sub syschk '---------------- ' Define objects '---------------- ' DISK Const HARD_DISK = 3 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "") ' TCP/IP strComputer = "." Set objWMIService = GetObject _ ("winmgmts:" & "!\\" & strComputer & "\root\cimv2") Set colAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True") ' Check current folder myPGM1= "\"& myPGM myDIR= Replace(WScript.ScriptFullName,myPGM1,"") myTXT_NAME= myDIR & "\"& TXT_NAME myFTPPARM = myDIR & "\"& FTPPARM myEVENTFILE = myDIR & "\"& EVENTF_NAME FTPCOM = "ftp -n -i -v -s:"& myDIR & "\"& FTPPARM 'FTP command with absolute path On Error Resume Next ' REPORT FILE Set objFS1 = CreateObject("Scripting.FileSystemObject") Set objFile = objFS1.CreateTextFile(myTXT_NAME, True) If Err.Number <> 0 Then myERR = myERR & vbCR & "text file can not create. file="& myTXT_NAME & " " & Now Exit Sub End If ' FTP command file Set objFS2 = CreateObject("Scripting.FileSystemObject") Set objFile2 = objFS2.CreateTextFile(myFTPPARM, True) If Err.Number <> 0 Then myERR = myERR & vbCR & "ftp file can not create. file="& myFTPPARM & " " & Now Exit Sub End If '--------------------- ' START main process '--------------------- ' Hedline of report file 'objFile.WriteLine(myPGM &" VER:" & PGM_VER &" Server monitor report "& Now ) myDate = Date myTime = Now myHour = Hour(myTime) If myHour < 10 Then myHour = "0"& myHour End If myMinute = Minute(myTime) If myMinute < 10 Then myMinute = "0"& myMinute End If mySecond = Second(myTime) If mySecond < 10 Then mySecond = "0"& mySecond End If objFile.WriteLine(myPGM &" VER:" & PGM_VER &" Server monitor report "& Date & " "& myHour & ":"& myMinute & ":"& mySecond ) objFile.WriteLine("Current folder:"& myDIR ) ' Computer type ... WINS,DNS,,,, mySQL = "" strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputers = objWMIService.ExecQuery _ ("Select DomainRole from Win32_ComputerSystem") For Each objComputer in colComputers Select Case objComputer.DomainRole Case 0 strComputerRole = "Standalone Workstation" Case 1 strComputerRole = "Member Workstation" Case 2 strComputerRole = "Standalone Server" Case 3 strComputerRole = "Member Server" Case 4 strComputerRole = "Backup Domain Controller" Case 5 strComputerRole = "Primary Domain Controller" End Select objFile.WriteLine("Computer type:"& strComputerRole) Next strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name = 'MSSQLServer'") If colServices.Count > 0 Then For Each objService in colServices objFile.WriteLine("SQL Server is " & objService.State & ".") mySQL = objService.State Next Else objFile.WriteLine("SQL Server is not installed on this computer.") End If ' TCP/IP objFile.WriteLine("---------------------") objFile.WriteLine("Network informations ") objFile.WriteLine("---------------------") For Each objAdapter in colAdapters objFile.WriteLine("Host name: " & objAdapter.DNSHostName) if Not IsNull(objAdapter.DNSHostName) Then myHOSTNAME = objAdapter.DNSHostName End If objFile.WriteLine("DNS domain: " & objAdapter.DNSDomain) objFile.WriteLine("DNS suffix search list: " & objAdapter.DNSDomainSuffixSearchOrder) objFile.WriteLine("Description: " & objAdapter.Description) objFile.WriteLine("Physical address: " & objAdapter.MACAddress) objFile.WriteLine("DHCP enabled: " & objAdapter.DHCPEnabled) If Not IsNull(objAdapter.IPAddress) Then For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress) objFile.WriteLine("IP address: " & objAdapter.IPAddress(i) ) Next End If If Not IsNull(objAdapter.IPSubnet) Then For i = LBound(objAdapter.IPSubnet) To UBound(objAdapter.IPSubnet) objFile.WriteLine("Subnet: " & objAdapter.IPSubnet(i) ) Next End If If Not IsNull(objAdapter.DefaultIPGateway) Then For i = LBound(objAdapter.DefaultIPGateway) To UBound(objAdapter.DefaultIPGateway) objFile.WriteLine("Default gateway: " & objAdapter.DefaultIPGateway(i) ) Next End If objFile.WriteLine("DHCP server: " & objAdapter.DHCPServer) If Not IsNull(objAdapter.DNSServerSearchOrder) Then For i = LBound(objAdapter.DNSServerSearchOrder) To UBound(objAdapter.DNSServerSearchOrder) objFile.WriteLine("DNS server: " & objAdapter.DNSServerSearchOrder(i) ) Next End If objFile.WriteLine("Primary WINS server: " & objAdapter.WINSPrimaryServer ) objFile.WriteLine("Secondary WINS server: " & objAdapter.WINSSecondaryServer ) objFile.WriteLine("Lease obtained: " & objAdapter.DHCPLeaseObtained ) objFile.WriteLine("Lease expires: " & objAdapter.DHCPLeaseExpires ) Next ' DISK objFile.WriteLine("------------------") objFile.WriteLine("DISK informations") objFile.WriteLine("------------------") For Each objDisk in colDisks myFREEDISK = Int( objDisk.FreeSPace / 1024 / 1024 ) objFile.WriteLine("DeviceID: "& objDisk.DeviceID & " Free_Disk_Space: "& myFREEDISK &"MB") Next ' PROCESS objFile.WriteLine("--------------------") objFile.WriteLine("Process informations") objFile.WriteLine("--------------------") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'sqlservr.exe'") If colProcesses.Count = 0 Then objFile.WriteLine("sqlservr.exe is not running.") Else objFile.WriteLine("sqlservr.exe is running.") End If Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'sqlmangr.exe'") If colProcesses.Count = 0 Then objFile.WriteLine("sqlmangr.exe is not running.") Else objFile.WriteLine("sqlmangr.exe is running.") End If ' SOFTWARE informations objFile.WriteLine("--------------------") objFile.WriteLine("Software information") objFile.WriteLine("--------------------") ' Operationg system myOSNAME="" strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems objFile.WriteLine("OS:"& objOperatingSystem.Caption & " " & objOperatingSystem.Version ) myOSNAME = objOperatingSystem.Caption Next ' Service pack strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems objFile.WriteLine( "Service pack:"& objOperatingSystem.ServicePackMajorVersion _ & "." & objOperatingSystem.ServicePackMinorVersion ) Next ' Hardware information objFile.WriteLine( "----------------------" ) objFile.WriteLine( "HARDWARE informations" ) objFile.WriteLine( "----------------------" ) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colSettings objFile.WriteLine( "System Name: " & objComputer.Name ) objFile.WriteLine( "System Manufacturer: " & objComputer.Manufacturer ) objFile.WriteLine( "System Model: " & objComputer.Model ) objFile.WriteLine( "Time Zone: " & objComputer.CurrentTimeZone ) objFile.WriteLine( "Total Physical Memory: " & _ objComputer.TotalPhysicalMemory ) Next Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_Processor") For Each objProcessor in colSettings objFile.WriteLine( "System Type: " & objProcessor.Architecture ) objFile.WriteLine( "Processor: " & objProcessor.Description ) Next Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_BIOS") For Each objBIOS in colSettings objFile.WriteLine( "BIOS Version: " & objBIOS.Version ) Next strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colChassis = objWMIService.ExecQuery _ ("Select * from Win32_SystemEnclosure") For Each objChassis in colChassis For i = Lbound(objChassis.ChassisTypes) to Ubound(objChassis.ChassisTypes) objFile.WriteLine( "Computer chassis: "& objChassis.ChassisTypes(i) ) Next Next strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMice = objWMIService.ExecQuery _ ("Select * from Win32_PointingDevice") For Each objMouse in colMice objFile.WriteLine( "Hardware Type: " & objMouse.HardwareType ) objFile.WriteLine( "Number of Buttons: " & objMouse.NumberOfButtons ) objFile.WriteLine( "Status: " & objMouse.Status ) objFile.WriteLine( "PNP Device ID: " & objMouse.PNPDeviceID ) Next ' Process-Performance objFile.WriteLine( "--------------" ) objFile.WriteLine( "Heavy Process " ) objFile.WriteLine( "--------------" ) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery _ ("Select * from Win32_Process") For Each objProcess in colProcessList If objProcess.PageFileUsage > 10000000 Then objFile.WriteLine( "Process: " & objProcess.Name ) objFile.WriteLine( "Process ID: " & objProcess.ProcessID ) objFile.WriteLine( "Thread Count: " & objProcess.ThreadCount ) objFile.WriteLine( "Page File Size: " & objProcess.PageFileUsage ) objFile.WriteLine( "Page Faults: " & objProcess.PageFaults ) objFile.WriteLine( "Working Set Size: " & objProcess.WorkingSetSize ) End If Next objFile.WriteLine( "------------------" ) objFile.WriteLine( "Logn Time process " ) objFile.WriteLine( "------------------" ) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_process") For Each objProcess in colProcesses sngProcessTime = ( CSng(objProcess.KernelModeTime) + _ CSng(objProcess.UserModeTime)) / 10000000 If sngProcessTime > 0.5 Then objFile.WriteLine( objProcess.name & VbTab & sngProcessTime ) End If Next ' Check all printers objFile.WriteLine("--------------------") objFile.WriteLine("Printers information") objFile.WriteLine("--------------------") strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters objFile.WriteLine( "Name: " & objPrinter.Name ) objFile.WriteLine( "Location: " & objPrinter.Location ) Select Case objPrinter.PrinterStatus Case 1 strPrinterStatus = "Other" Case 2 strPrinterStatus = "Unknown" Case 3 strPrinterStatus = "Idle" Case 4 strPrinterStatus = "Printing" Case 5 strPrinterStatus = "Warmup" End Select objFile.WriteLine( "Printer Status: " & strPrinterStatus ) objFile.WriteLine( "Server Name: " & objPrinter.ServerName ) objFile.WriteLine( "Share Name: " & objPrinter.ShareName ) objFile.WriteLine( " " ) Next ' Shered folder objFile.WriteLine("-------------") objFile.WriteLine("Shared folder") objFile.WriteLine("-------------") strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colShares = objWMIService.ExecQuery("Select * from Win32_Share") For each objShare in colShares objFile.WriteLine( "AllowMaximum: " & vbTab & objShare.AllowMaximum ) ' objFile.WriteLine( "Caption: " & vbTab & objShare.Caption ) objFile.WriteLine( "MaximumAllowed: " & vbTab & objShare.MaximumAllowed ) objFile.WriteLine( "Name: " & vbTab & objShare.Name ) objFile.WriteLine( "Path: " & vbTab & objShare.Path ) objFile.WriteLine( "Type: " & vbTab & objShare.Type ) Next ' SQL server agent mySQLLOG0S = "" mySQLLOG1S = "" mySQLLOG2S = "" mySQLLOG3S = "" mySQLLOG4S = "" mySQLLOG5S = "" mySQLLOG6S = "" If mySQL = "Running" Then ' check directory mySQLLOG0 = "D:\MSSQL7\LOG\ERRORLOG" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG0) Then mySQLLOG0S = "ok" Else mySQLLOG0 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG0) Then mySQLLOG0S = "ok" Else mySQLLOG0 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG0) Then mySQLLOG0S = "ok" Else mySQLLOG0 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG0) Then mySQLLOG0S = "ok" Else mySQLLOG0S = "ng" End If End If End If End If mySQLLOG1 = "D:\MSSQL7\LOG\ERRORLOG.1" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG1) Then mySQLLOG1S = "ok" Else mySQLLOG1 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.1" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG1) Then mySQLLOG1S = "ok" Else mySQLLOG1 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.1" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG1) Then mySQLLOG1S = "ok" Else mySQLLOG1 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.1" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG1) Then mySQLLOG1S = "ok" Else mySQLLOG1S = "ng" End If End If End If End If mySQLLOG2 = "D:\MSSQL7\LOG\ERRORLOG.2" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG2) Then mySQLLOG2S = "ok" Else mySQLLOG2 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.2" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG2) Then mySQLLOG2S = "ok" Else mySQLLOG2 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.2" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG2) Then mySQLLOG2S = "ok" Else mySQLLOG2 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.2" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG2) Then mySQLLOG2S = "ok" Else mySQLLOG2S = "ng" End If End If End If End If mySQLLOG3 = "D:\MSSQL7\LOG\ERRORLOG.3" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG3) Then mySQLLOG3S = "ok" Else mySQLLOG3 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.3" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG3) Then mySQLLOG3S = "ok" Else mySQLLOG3 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.3" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG3) Then mySQLLOG3S = "ok" Else mySQLLOG3 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.3" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG3) Then mySQLLOG3S = "ok" Else mySQLLOG3S = "ng" End If End If End If End If mySQLLOG4 = "D:\MSSQL7\LOG\ERRORLOG.4" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG4) Then mySQLLOG4S = "ok" Else mySQLLOG4 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.4" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG4) Then mySQLLOG4S = "ok" Else mySQLLOG4 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.4" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG4) Then mySQLLOG4S = "ok" Else mySQLLOG4 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.4" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG4) Then mySQLLOG4S = "ok" Else mySQLLOG4S = "ng" End If End If End If End If mySQLLOG5 = "D:\MSSQL7\LOG\ERRORLOG.5" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG5) Then mySQLLOG5S = "ok" Else mySQLLOG5 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.5" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG5) Then mySQLLOG5S = "ok" Else mySQLLOG5 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.5" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG5) Then mySQLLOG5S = "ok" Else mySQLLOG5 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.5" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG5) Then mySQLLOG5S = "ok" Else mySQLLOG5S = "ng" End If End If End If End If mySQLLOG6 = "D:\MSSQL7\LOG\ERRORLOG.6" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG6) Then mySQLLOG6S = "ok" Else mySQLLOG6 = "D:\SQL2k\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.6" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG6) Then mySQLLOG6S = "ok" Else mySQLLOG6 = "D:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.6" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG6) Then mySQLLOG6S = "ok" Else mySQLLOG6 = "D:\Microsoft SQL Server\MSSQL\LOG\ERRORLOG.6" Set objFSS = CreateObject("Scripting.FileSystemObject") If objFSS.FileExists(mySQLLOG6) Then mySQLLOG6S = "ok" Else mySQLLOG6S = "ng" End If End If End If End If End If ' Services objFile.WriteLine( "--------" ) objFile.WriteLine( "Services" ) objFile.WriteLine( "--------" ) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery _ ("Select * from Win32_Service") For Each objService in colRunningServices objFile.WriteLine( objService.DisplayName & VbTab & objService.State ) If objService.DisplayName = "UPS - APC PowerChute plus" Then myUPS = "running" End If Next ' UPS/Powerchute information 'MsgBox("myUPS:" & myUPS) If myUPS = "running" Then ' check UPS log file strPath1 = "C:\Program Files\Pwrchute\pwrchute.log" strPath2 = "D:\Program Files\Pwrchute\pwrchute.log" Set objFSU = CreateObject("Scripting.FileSystemObject") If objFSU.FileExists(strPath1) Then myUPSF = strPath1 Else If objFSU.FileExists(strPath2) Then myUPSF = strPath2 Else myUPSF = "" End If End If End If ' Event Log if windows 2003 server If Left( myOSNAME,35) = "Microsoft(R) Windows(R) Server 2003" Then myEVENTS = "ok" Set objFS5 = CreateObject("Scripting.FileSystemObject") Set objFile5 = objFS5.CreateTextFile(myEVENTFILE, True) If Err.Number <> 0 Then myERR = myERR & vbCR & "event text file can not create. file="& myEVENTFILE & " " & Now Exit Sub End If objFile5.WriteLine(myPGM &" VER:" & PGM_VER &" Server monitor report "& Date & " "& myHour & ":"& myMinute & ":"& mySecond ) objFile5.WriteLine("Current folder:"& myDIR ) objFile5.WriteLine("myOSNAME:" & myOSNAME ) objFile5.WriteLine("--------") objFile5.WriteLine("Eventlog") objFile5.WriteLine("--------") Const CONVERT_TO_LOCAL_TIME = True Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime") Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime") 'DateToCheck = CDate("06/16/2004") myDate = Right( myDate,8) myDAYXY = Mid( myDate,1,2 ) myDAYXM = Mid( myDate,4,2 ) myDAYXD = Mid( myDate,7,2 ) myDAYXY = "20" & myDAYXY myDAYX = myDAYXM & "/" & myDAYXD & "/" & myDAYXY objFile5.WriteLine("myDAYX:" & myDAYX & " myDate:" & myDate ) DateToCheck = CDate( myDAYX ) dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME dtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent Where TimeWritten >= '" _ & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'") For each objEvent in colEvents If objEvent.Type <> "̊č" Then objFile5.WriteLine( "Category: " & objEvent.Category ) objFile5.WriteLine( "Computer Name: " & objEvent.ComputerName ) objFile5.WriteLine( "Event Code: " & objEvent.EventCode ) objFile5.WriteLine( "Message: " & objEvent.Message ) objFile5.WriteLine( "Record Number: " & objEvent.RecordNumber ) objFile5.WriteLine( "Source Name: " & objEvent.SourceName ) objFile5.WriteLine( "Time Written: " & objEvent.TimeWritten ) objFile5.WriteLine( "Event Type: " & objEvent.Type ) objFile5.WriteLine( "User: " & objEvent.User ) objFile5.WriteLine( objEvent.LogFile ) End If Next objFile5.Close End If ' write if re-schedule If schdSW = "on" Then objFile.WriteLine(" ") objFile.WriteLine("re schedule SW=" & schdSW ) objFile.WriteLine(" submit time=" & schdDATE & " " & schdTIMES & _ " - " & schdTIMEE ) Call rschedule End If objFile.Close ' REPORT by FTP and update script If Not IsNull(myHOSTNAME) Then ' Create FTP command file: FTPCOM objFile2.WriteLine("open "& FTPSRVR) objFile2.WriteLine("user ftpuser ftppasswrd") objFile2.WriteLine("lcd "& myDIR) objFile2.WriteLine("cd /ftpuser/server_monitor") objFile2.WriteLine("ascii") objFile2.WriteLine("delete "& myHOSTNAME &"_24.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_23.txt " & myHOSTNAME &"_24.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_22.txt " & myHOSTNAME &"_23.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_21.txt " & myHOSTNAME &"_22.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_20.txt " & myHOSTNAME &"_21.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_19.txt " & myHOSTNAME &"_20.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_18.txt " & myHOSTNAME &"_19.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_17.txt " & myHOSTNAME &"_18.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_16.txt " & myHOSTNAME &"_17.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_15.txt " & myHOSTNAME &"_16.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_14.txt " & myHOSTNAME &"_15.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_13.txt " & myHOSTNAME &"_14.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_12.txt " & myHOSTNAME &"_13.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_11.txt " & myHOSTNAME &"_12.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_10.txt " & myHOSTNAME &"_11.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_09.txt " & myHOSTNAME &"_10.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_08.txt " & myHOSTNAME &"_09.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_07.txt " & myHOSTNAME &"_08.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_06.txt " & myHOSTNAME &"_07.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_05.txt " & myHOSTNAME &"_06.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_04.txt " & myHOSTNAME &"_05.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_03.txt " & myHOSTNAME &"_04.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_02.txt " & myHOSTNAME &"_03.txt") objFile2.WriteLine("rename "& myHOSTNAME &"_01.txt " & myHOSTNAME &"_02.txt") objFile2.WriteLine("rename "& myHOSTNAME &".txt " & myHOSTNAME &"_01.txt") objFile2.WriteLine("put "& TXT_NAME & " "& myHOSTNAME &".txt") If mySQLLOG0S = "ok" Then objFile2.WriteLine("put """& mySQLLOG0 & """ "& myHOSTNAME &"_sqllog00.txt") End If If mySQLLOG1S = "ok" Then objFile2.WriteLine("put """& mySQLLOG1 & """ "& myHOSTNAME &"_sqllog01.txt") End If If mySQLLOG2S = "ok" Then objFile2.WriteLine("put """& mySQLLOG2 & """ "& myHOSTNAME &"_sqllog02.txt") End If If mySQLLOG3S = "ok" Then objFile2.WriteLine("put """& mySQLLOG3 & """ "& myHOSTNAME &"_sqllog03.txt") End If If mySQLLOG4S = "ok" Then objFile2.WriteLine("put """& mySQLLOG4 & """ "& myHOSTNAME &"_sqllog04.txt") End If If mySQLLOG5S = "ok" Then objFile2.WriteLine("put """& mySQLLOG5 & """ "& myHOSTNAME &"_sqllog05.txt") End If If mySQLLOG6S = "ok" Then objFile2.WriteLine("put """& mySQLLOG6 & """ "& myHOSTNAME &"_sqllog06.txt") End If If myUPSF <> "" Then objFile2.WriteLine("put """& myUPSF & """ "& myHOSTNAME &"_upslog.txt") End If ' Eventlog If myEVENTS = "ok" Then objFile2.WriteLine("put """& myEVENTFILE & """ "& myHOSTNAME &"_eventlog.txt") End If If myHOSTNAME = "J0155302" Then objFile2.WriteLine("pwd") Else objFile2.WriteLine("cd /ftpuser/server_monitor/scripts") objFile2.WriteLine("mget *.vbs") End If objFile2.WriteLine("bye") objFile2.Close ' FTP send the report(text file) Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run FTPCOM, 0 End If End Sub ' Re Schedule task ' Sub rschedule() On Error Resume Next ' current system date myDate = Date myTime = Now myHour = Hour(myTime) If myHour < 10 Then myHour = "0"& myHour End If myMinute = Minute(myTime) If myMinute < 10 Then myMinute = "0"& myMinute End If mySecond = Second(myTime) If mySecond < 10 Then mySecond = "0"& mySecond End If ' check date and time If left(myDate,10) <> schdDATE Then Exit Sub End If If left(schdTIMES,2) > left(schdTIMEE,2) Then Exit Sub End If If left(myHour,2) < left(schdTIMES,2) Then Exit Sub End If If left(myHour,2) > left(schdTIMEE,2) Then Exit Sub End If ' create commands myVBSCOM1 = "cmd /c " & myDIR & "\" & "ftp-sys-chk-schedule-cancel.vbs" myVBSCOM2 = "cmd /c " & myDIR & "\" & "ftp-sys-chk-schedule.vbs" MsgBox("command1 is " & myVBSCOM1 & vbCR & "command2 is " & myVBSCOM2) ' execute commands ' Set WshShell = WScript.CreateObject("WScript.Shell") ' WshShell.Run myVBSCOM1,0,True ' Set WshShell = WScript.CreateObject("WScript.Shell") ' WshShell.Run myVBSCOM2,0 End Sub