Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Trying to monitor folder content using a vbs script

$
0
0

Hi guys,

I've found quite a lot of scripts that should have helped to reach my goal, but I didn't manage to adapt it.

My need is to check how my daily loading (from both operational system and then accounting system) has ended in the night.

Currently I do it manually every morning and just checking it takes me 30 minutes (in case everything is ok!). So my plan was to script the several steps I check every morning in a .wsf script (using vb) that I could run through a scheduled task every morning.
As so, it would send me a mail listing for each checked step what having found / missing, so no mail would mean everything went well no need to loose my time to check on it (because hopefully it happens :) ).

My checking steps are the following:

1. For the operational system:

I look in a database the date of last integrated file of each of my local operational systems,

If any isn't at the date of today, then I check that it's not stuck into my working folder (in case it is I will manually fix it and relaunch data loading),

If there is no file stuck in my working folder, first thing I need to check is that it has been well transferred from my XFB server.

If no file stuck in my XFB server, it means that my missing file hasn't been generated / sent by my local operational system so I will ask to my correspondent to check on that.

2. For my  accounting system, I daily received files from my local accounting systems:

I look on my archive folder (named Hist, where all previous loaded files are stored), to check if all sub-folder have been updated today (if yes, it means daily data loading is OK)

If there is one not up to date, I'll check that it my processing loading folder (named In, where all files to be loaded are stored) hasn't been locked due to a corrupted file,

If there is none, I'll check that it has been well transferred from my XFB server.

If no file stuck in my XFB server, it means that my missing file hasn't been generated / sent by my local accounting system and I'll need to look on it manually.

Here is the script I've tried to write, but at the first moment I try to run it, an error is raised at a Dim statement declaration and I really to see why...

If anyone could help with this, it would be much appreciated :).

<package><job id="DailyMonitoring"><object id="objCnx" progid="ADODB.Connection"/><object id="objRs" progid="ADODB.Recordset"/><object id="objShell" progid="WScript.Shell"/><object id="objFso" progid="Scripting.FileSystemObject"/><script language = "VBScript">
			Const sAPP22PEGFolder = "\\LoadingServer\E$\INFOCENTRE\LOTS\"   'APP22 PEG folder to check if no file stuck
			Const sAPP22SUNHistFolder = "\\LoadingServer\E$\INF_SUN\Hist\"   'APP22 SUN Hist folder to check if all subfolders are up to date
			Const sAPP22SUNInFolder = "\\LoadingServer\E$\INF_SUN\In\"   'APP22 SUN IN folder to check if no files stuck
			Const sAPP78PEGFolder = "\\XFBserver\D$\Infocentre\PEGASE\Batch\"   'XFB server PEG folder to check if no file stuck
			Const sAPP78SUNFolder = "\\XFBserver\D$\Infocentre\INFSUN\Batch\"   'XFB server SUN folder to check if no file stuck
			Const sAPP45 = "AccountingDBServer"   'APP45 SUN DB server
			Const sOutput  = "\\LoadingServer\E$\MonitoringResult.txt"  'The name of The output file
			Const mstrPeg_Host = "OperationalDBServer"
			Const mstrBD_SQL = "INFOCENTRE"
			Const mstrUser = "sa"
			Const mstrPwd = "somepw"
			Dim oFSO, oOutput, oFolderAPP22, oFolderAPP78
			Dim strSQLPEGMissingLots
			Const CST_SQLOLEDB_CNX = "Provider=SQLOLEDB;Data Source=%1;Initial Catalog=%2;User ID=%3;Password=%4;"
			strCnx = Replace(CST_SQLOLEDB_CNX, "%1", mstrPeg_Host)
			strCnx = Replace(strCnx, "%2", mstrBD_SQL)
			strCnx = Replace(strCnx, "%3", mstrUser)
			strCnx = Replace(strCnx, "%4", mstrPwd)
			objCnx.Open strCnx
			Set oFSO = CreateObject("Scripting.FileSystemObject")
			Set oOutput = oFSO.CreateTextFile(sOutput, True)
			oOutput.WriteLine "Start Daily PEG Loading check on " & Date() & "\r\n\r\n"
			On Error Resume Next
			Dim countLOTSFiles As Integer
			Dim countPEGBatchFiles As Integer
			Dim countSUNBatchFiles As Integer
			set countLOTSFiles = 0
			set countPEGBatchFiles = 0
			set countSUNBatchFiles = 0
			strSQLPEGMissingLots = "Use INFOCENTRE SELECT distinct f.[C_CODE_BASE] ,o.entity ,f.[C_NUM_LOT] ,convert(char(8),f.[C_DATE_LOT],112)+'\r\n' as C_DATE  FROM [INFOCENTRE].[dbo].[LOTS] f inner join (select [C_CODE_BASE] ,max ([C_NUM_LOT]) lot FROM [INFOCENTRE].[dbo].[LOTS] group by [C_CODE_BASE]) s on  s.[C_CODE_BASE]=f.[C_CODE_BASE] and s.lot=f.[C_NUM_LOT] left outer join [ASPAC_Reference].[dbo].[DIM_Organization] o on f.c_code_base=o.codebase where s.C_CODE_BASE not in ('auaau','APSGC') and substring(convert(char(8),f.[C_DATE_LOT],112),1,8) <> convert(char(8),getdate(),112) order by C_DATE, c_code_base"
			set RsPEGMissingLots = objCnx.Execute(strSQLPEGMissingLots)
			WriteLog("PEG LOTS missing in database: \r\n"& RsPEGMissingLots(0))
			If RsPEGMissingLots <> "" Then
				Set oFolderAPP22 = oFSO.GetFolder(sAPP22PEGFolder)
				If Err.number <> 0 Then
					oOutput.WriteLine "Cannot access " & sAPP22PEGFolder & " - " & Err.Description & "\r\n"
				Else
					oOutput.WriteLine "\r\n\r\n*** APP22 LOTS Folder content: ***\r\n"
					For Each oFileAPP22 In oFolderAPP22.Files
						'If oFileAPP22.GetExtensionName() = "txt" Then
							' voir pour appel du renamefile.exe
							oOutput.WriteLine oFileAPP22.path
							Set countLOTSFiles = countLOTSFiles + 1
						'End If
					Next
					If countLOTSFiles = 0 Then
						oOutput.WriteLine "\r\n*** No file stuck in APP22 LOTS Folder ***\r\n"
						On Error Resume Next
						'start check APP78 PEG Folder
						Set oFolderAPP78 = oFSO.GetFolder(sAPP78PEGFolder)
						If Err.number <> 0 Then
							oOutput.WriteLine "Cannot access " & sAPP78PEGFolder & " - " & Err.Description & "\r\n"
						Else
							oOutput.WriteLine "*** APP78 PEG Batch Folder content: ***\r\n"
							For Each oFileAPP78 In oFolderAPP78.Files
								oOutput.WriteLine oFileAPP78.path
								oOutput.WriteLine "\r\n"
								Set countPEGBatchFiles = countPEGBatchFiles + 1
							Next
						End If
						If countPEGBatchFiles = 0 Then
							oOutput.WriteLine "\r\nNo file stuck in APP78 PEG Batch Folder"
						End If
						On Error Goto 0
					End If
				End If
				On Error Goto 0
			Else
				oOutput.WriteLine "\r\n*** PEG Daily Loading OK ***\r\n"
			End If
			oOutput.WriteLine "\r\n*** PEG Daily Loading ended ***\r\n"
			'End of PEG Daily Loading monitoring
			'Start SUN Daily Loading monitoring
			oOutput.WriteLine "\r\n*** Start Daily SUN Loading check on " & Date() & " ***\r\n"

			'-Check APP22 SUN Hist folder
			Dim oFolderSUNHistFolders, oSUNHistFolder, oSUNInFolders, oFileSUNIn
			Dim dateModified
			Dim countSUNHistFiles As Integer
			Dim countSUNInFiles As Integer
			set countSUNHistFiles = 0
			set countSUNInFiles = 0
			On Error Resume Next
			Set oSUNHistFolders = oFSO.GetFolder(sAPP22SUNHistFolder)
			If Err.Number <> 0 Then
				oOutput.WriteLine "Cannot access " & sAPP22SUNHistFolder & " folder - " & Err.Description & "\r\n"
			Else
				oOutput.WriteLine "*** APP22 SUN Hist Folder content: ***\r\n"
				For Each oSUNHistFolder In oSUNHistFolders
					Do
					dateModified = oFSO.GetFolder(oSUNHistFolder.Path).DateLastModified
					If Err.Number <> 0 Then
						oOutput.WriteLine oSUNHistFolder.Path & " folder: Cannot get the DataLastModified property\r\n"
						Exit Do
					End If
					If dateModified < Date() Then
						oOutput.WriteLine oSUNHistFolder.Path & " last updated on " & dateModified & "\r\n"
						Set countSUNHistFiles = countSUNHistFiles + 1
					End If
					'Check
					Loop Until True
				Next
				If countSUNHistFiles > 0 Then
					oOutput.WriteLine "Files missing in APP22 SUN Hist Folder"
					'start check no files stuck in SUN In Folder
					On Error Resume Next
					Set oSUNInFolders = oFSO.GetFolder(sAPP22SUNInFolder)
					If Err.Number <> 0 Then
						oOutput.WriteLine "Cannot access " & sAPP22SUNInFolder & " folder - " & Err.Description & "\r\n"
						Exit Do
					End If
					oOutput.WriteLine "\r\n*** APP22 SUN In Folder content: ***\r\n"
					For Each oFileSUNIn In oSUNInFolders.Files
					'If oFileAPP22.GetExtensionName() = "txt" Then
						' voir pour appel du renamefile.wsf
						oOutput.WriteLine oFileSUNIn.path
						Set countSUNInFiles = countSUNInFiles + 1
					'End If
					Next
					If countSUNInFiles = 0 Then
						oOutput.WriteLine "\r\nNo file stuck in APP22 SUN In Folder"
						On Error Resume Next
						'start check APP78VM SUN Folder
						Set oFolderAPP78 = oFSO.GetFolder(sAPP78SUNFolder)
						If Err.number <> 0 Then
							oOutput.WriteLine "Cannot access " & sAPP78SUNFolder & " - " & Err.Description & "\r\n"
						Else
							oOutput.WriteLine "*** APP78 SUN Batch Folder content: ***\r\n"
							For Each oFileAPP78 In oFolderAPP78.Files
								oOutput.WriteLine oFileAPP78.path
								oOutput.WriteLine "\r\n"
								Set countSUNBatchFiles = countSUNBatchFiles + 1
							Next
						End If
						If countSUNBatchFiles = 0 Then
							oOutput.WriteLine "\r\nNo file stuck in APP78 SUN Batch Folder, need to check local SUN server"
						End If
						On Error Goto 0
					End If
				Else
					oOutput.WriteLine "\r\n*** SUN Daily Loading OK ***\r\n"
				End If
				On Error Goto 0
			End If
			oOutput.WriteLine "\r\n*** SUN Daily Loading ended ***\r\n"
			oOutput.Close
			objCnx.close</script></job></package>


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>