'========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM) ' ' NAME: NTSMF_COPY ' ' AUTHOR: Paul Jaffray ' Promedica Health System, Inc. ' paul.jaffray@promedica.org ' ' DATE : 10/15/2000 ' ' COMMENT: Copies and combines NTSMF data from servers to a single point ' mailing status requires the SMTP service to be loaded and active ' '========================================================================== ' Option Explicit dim srvsource ' drive (or UNC) path to the list of servers dim targetdir ' drive (or UNC) path where files are copied to dim emailtofield ' email address(es) of status report recipients dim logmsg ' message to be written to the application event log dim rlogmsg ' "running Log Message" all messages collected and e-mailed ' as a status report dim filedate ' set so that only today's files are copied dim ftploc ' where S390 ftps the daily file from ' targetdir = "C:\NTSMF_TEMP" srvsource = "C:\Automation\Scripts\serverlist.txt" emailtofield = "nomail" 'emailtofield = "Paul.Jaffray@promedica.org;jon.knapp@promedica.org" filedate = "" ' initialized as null ftploc = "noftp" ' ' set shell object set ws = WScript.CreateObject("WScript.Shell") ' set file system object set fso = CreateObject("Scripting.FileSystemObject") ' ' log start of script logmsg = date & " " & time & " NTSMF_COPY - Script started" rlogmsg = logmsg & vbCrLf ws.LogEvent 0,logmsg ' call deloldfiles ' call datesetup ' ' copy files looping on a list of servers from a text file ' if (fso.FileExists(srvsource)) = false then logmsg = date & " " & time & " NTSMF_COPY - Server List Does Not Exist!!!" rlogmsg = rlogmsg & logmsg & vbCrLf ws.LogEvent 1, logmsg emailstatus = " Failed - No Server List!" call SendEMail() WScript.Quit 1 end if ' set txtStream = fso.OpenTextFile(srvsource) Do While Not (txtStream.atEndOfStream) srvname = txtStream.ReadLine ' ' check for yesterday's data in the \PREVIOUS directory ' fromwhere = "PREVIOUS" call copyfiles ' ' check for yesterday's data in the \ARCHIVE directory ' fromwhere = "ARCHIVE" call copyfiles Loop ' ' combine all separate files into a single daily file call CatFiles ' ' Clean out ftp host of old files if (fso.FolderExists(ftploc)) then set ofolder = fso.GetFolder(ftploc) set ofiles = ofolder.Files for each i in ofiles file1 = ftploc & "\" & i.Name fso.DeleteFile file1 next end if ' ' copy combined file to ftp host for MF transfer If ftploc <> "noftp" Then set fin = fso.GetFile("C:\MXG\SMFDATA\NTSMF" & filedate & ".SMF") fin.Copy ftploc & "\NTSMF.XMT" End If ' ' copy combined file to AIX SAMBA host for sharing and archiving fin.Copy "\\PHSAIX004\NTSMF\NTSMF" & filedate & ".SMF" ' ' log end of script logmsg = date & " " & time & " NTSMF_COPY - Script ended" rlogmsg = rlogmsg & logmsg & " " & vbCrLf ws.LogEvent 0, logmsg rlogmsg = rlogmsg & date & " " & time & " NTSMF_COPY - created - c:\mxg\smfdata\ntsmf" & filedate & ".SMF"& " " & vbCrLf emailstatus = " - Completed" If emailtofield <> "nomail" Then call SendEMail() End If ' ' ' Program Subroutines ' sub deloldfiles ' get a list of files at the target and delete each one if (fso.FolderExists(targetdir)) then set ofolder = fso.GetFolder(targetdir) set ofiles = ofolder.Files for each i in ofiles file1 = targetdir & "\" & i.Name fso.DeleteFile file1 next else logmsg = date & " " & time & " NTSMF_COPY - Target Directory Does Not Exist!!!" rlogmsg = rlogmsg & logmsg & " " & vbCrLf ws.LogEvent 1,logmsg emailstatus = " failed on Target Directory" call SendEMail() WScript.Quit 1 end if end sub ' ' ' sub datesetup ' setup date part of filename for comparison filedate = "." & Year(date - 1) if Month(date - 1) >= 10 then filedate = filedate & Month(date - 1) else filedate = filedate & "0" & Month(date - 1) end if if Day(date - 1) >= 10 then filedate = filedate & Day(date - 1) else filedate = filedate & "0" & Day(date - 1) end if end sub ' ' sub copyfiles if (fso.FolderExists(srvname & "\NTSMF\DATA\" & fromwhere)) then set ofolder = fso.GetFolder(srvname & "\NTSMF\DATA\" & fromwhere) set ofiles = ofolder.Files copyflag = false for each i in ofiles if instr(1,i.Name,filedate,1) > 0 then file1 = srvname & "\NTSMF\DATA\" & fromwhere & "\" & i.Name set ofile = fso.GetFile(file1) ofile.Copy targetdir & "\" & i.Name copyflag = true end if next if fromwhere = "PREVIOUS" and copyflag = false then logmsg = date & " " & time & " NTSMF_COPY - No PREVIOUS data- " & srvname rlogmsg = rlogmsg & logmsg & " " & vbCrLf ws.LogEvent 1,logmsg end if if fromwhere = "ARCHIVE" and copyflag = true then logmsg = date & " " & time & " NTSMF_COPY - ARCHIVE data- " & srvname rlogmsg = rlogmsg & logmsg & " " & vbCrLf ws.LogEvent 2,logmsg end if else logmsg = date & " " & time & " NTSMF_COPY - No " & fromwhere & " dir on " & srvname rlogmsg = rlogmsg & logmsg & " " & vbCrLf ws.LogEvent 1, logmsg end if end sub ' Sub SendEMail ' Send status messages to e-mail recipients Dim mailobj Set mailobj = CreateObject("cdonts.newmail") With mailobj .to = emailtofield .from = "Todd.Norton@promedica.org" .Subject = "NTSMF Status" & emailstatus .Body = rlogmsg .send end with set mailobj = nothing End Sub ' ' Sub CatFiles ' Combine all files into a single daily ntsmf file ' Set the directory for the input files set ofolder = fso.GetFolder(targetdir) ' get a list of all the files set ofiles = ofolder.Files ' now create the output file set fout = fso.OpenTextFile("C:\MXG\SMFDATA\NTSMF" & filedate & ".SMF",2,True) ' loop through all input files reading a line and writing it to the output file for each i in ofiles set fin = fso.OpenTextFile(targetdir & "\" & i.Name,1,True) Do While fin.AtEndOfStream <> True data = fin.ReadLine fout.WriteLine data loop fin.Close next fout.Close End Sub