'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Title : switch.vbs 'Description : Switch Oracle RDBMS logfiles (alert.log + listener.log) 'Author : Alessandro Benati 'Company : 'Created : 23/10/2003 'Rel. : 1.1 'Rel. Date : 24/10/2003 'Purpose : to copy into 'Note : produces a log of the executed actions in the execution ' directory named "switch.log" and an Application Log entry also '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Variables Dim WSHShell, objArgs, objFsys, clnFiles Dim strOracleRegKey, strOracleHome, strAlertLogPath, strLsnrLogPath Dim strDate, strAlertLogName, strFileName Public strLogFileName Set WSHShell = WScript.CreateObject("WScript.Shell") Set objArgs = WScript.Arguments Set objFsys = CreateObject("Scripting.FileSystemObject") strOracleRegKey = "HKLM\software\oracle\home0\ORACLE_HOME" strOracleHome = WSHShell.RegRead(strOracleRegKey) strAlertLogPath = "\bdump\" strLsnrLogPath = strOracleHome &"\network\log\" strDate = Year(Date()) &Month(Date()) &Day(Date()) strLogFileName = "switch.log" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Start Logging If Not objFsys.FileExists(strLogFileName) Then 'Il file di log NON esiste objFsys.CreateTextFile(strLogFileName) Else 'Il file di log esiste Set objFile = objFsys.GetFile(strLogFileName) objFile.Copy("switch" &strDate &".log") objFsys.DeleteFile(strLogFileName) objFsys.CreateTextFile(strLogFileName) End If Logger "################################################################################" Logger "# Log Started on " &FormatDateTime(Date(), vbLongDate) &" at " &Time() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Check if valid arguments ar passed on the command line If objArgs.Count = 0 Then Logger "" Logger "ERRORE 449 - Argomento non opzionale." EndScript Else strOracleSid = objArgs(0) Logger "" Logger "# PARAMETRI" Logger "OracleHome = " &strOracleHome Logger "OracleSid = " &UCase(objArgs(0)) Logger "AlertLogPath = " &strAlertLogPath Logger "LsnrLogPath = " &strLsnrLogPath End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Alert Log Logger "" Logger "# ALERT LOG" On Error Resume Next Set exist = objFsys.GetFolder(strAlertLogPath) If Err.Number <> 0 Then Logger "# ERRORE " &Err.Number &" - " &Err.Description &" " &strAlertLogPath WshShell.LogEvent 1, "Switch.vbs script failed with error " &Err.Number Err.Clear EndScript Else strAlertLogName = strAlertLogPath &strOracleSid &"ALRT.LOG" Set objFile = objFsys.GetFile(strAlertLogName) If Err.Number <> 0 Then Logger "ERRORE " &Err.Number &" - " &Err.Description &" " &strAlertLogName Logger "La procedura non puņ continuare." WshShell.LogEvent 1, "Switch.vbs script failed with error " &Err.Number Err.Clear EndScript Else objFile.Copy(strAlertLogName &"." &strDate) objFile.Delete Logger "1 File Copiato" Logger strAlertLogName &" -> " &strAlertLogName &"." &strDate Logger "" End If End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Listener Log Logger "" Logger "# LISTENER LOGS" On Error Resume Next Set exist = objFsys.GetFolder(strLsnrLogPath) If Err.Number <> 0 Then Logger "# ERRORE " &Err.Number &" - " &Err.Description &" " &strLsnrLogPath WshShell.LogEvent 1, "Switch.vbs script failed with error " &Err.Number Err.Clear EndScript Else Set clnFiles = objFsys.GetFolder(strLsnrLogPath).Files If clnFiles.Count = 0 Then Logger "# ERRORE " &Err.Number &" - " &Err.Description Logger "La cartella č vuota." WshShell.LogEvent 1, "Switch.vbs script failed with error " &Err.Number Else For Each objFile in clnFiles If Right(objFile.Name, 4) = ".log" Then objFile.Copy(strLsnrLogPath &objFile.Name &"." &strDate) Logger "1 File Copiato" Logger strLsnrLogPath &objFile.Name &" -> " &strLsnrLogPath &objFile.Name &"."&strDate Logger "" objFile.Delete End If Next End If End If WshShell.LogEvent 0, "Switch.vbs Script Completed Successfully" EndScript Sub EndScript() Logger "" Logger "# Log Stopped on " &FormatDateTime(Date(), vbLongDate) &" at " &Time() Logger "################################################################################" Set WSHShell = Nothing Set objFsys = Nothing Set clnFiles = Nothing Set objFile = Nothing WScript.quit(0) End Sub Sub Logger(strLine) Const ForReading=1 Const ForWriting=2 Const ForAppending=8 Const TristateUseDefault=-2 Const TristateTrue=-1 Const TristateFalse=0 Dim fso, f, ts Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFile(strLogFileName) Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault) ts.WriteLine(strLine) ts.Close End Sub