troubleshooting Question

convert java script to vbscript

Avatar of ISfish
ISfishFlag for Australia asked on
JavaScriptVB ScriptJScript
4 Comments2 Solutions1038 ViewsLast Modified:
hi guys,
An admin has left us and he wrote an admin script in .js that reads log files and pipes the results to a text file. A batch file is then called that sends me an email. The problem is,no one understands how it works
Can someone convert these 2 .js files into vbs scripts please and comment what each part is doing?
 the first code below runs first which is called by a batch file and the next code relates to the first
CODE1
oFSO = new ActiveXObject("Scripting.FileSystemObject");
oDate = new Date();
WSHShell = new ActiveXObject("WScript.Shell");

sLogDir = "c:\\admin\\logs\\";
sHomeDir = "c:\\admin\\scripts\\";
aDays = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
logsuffix = aDays[oDate.getDay()] + ((oDate.getDate() < 10) ? ("0" + oDate.getDate()) : oDate.getDate()) + (((oDate.getMonth() + 1) < 10) ? ( "0" + (oDate.getMonth() + 1)) : (oDate.getMonth() + 1)) + ".txt";
// logsuffix = "Thu0206.txt";

reFileSum = new RegExp("Files :[^0-9]+[0-9]+[^0-9]+[0-9]+[^0-9]+[0-9]+[^0-9]+([0-9]+)[^0-9]+([0-9]+)[^0-9]+[0-9]+", "ig");
reDirSum = new RegExp("Dirs :[^0-9]+[0-9]+[^0-9]+[0-9]+[^0-9]+[0-9]+[^0-9]+([0-9]+)[^0-9]+([0-9]+)[^0-9]+[0-9]+", "ig");
errorfile = oFSO.CreateTextFile(sHomeDir + "logcheck.txt", true);
errorfile.WriteLine("LogSuffix Date: " + logsuffix);
errorfile.WriteLine("Robocopy Replication logfile report for : " + oDate.toString() + "\r\n");
errorfile.WriteLine("---- Start ------");

oLogFolder = oFSO.GetFolder(sLogDir);
eFiles = new Enumerator(oLogFolder.Files);
while(!eFiles.atEnd())
{
      afile = eFiles.item();
      if(afile.Name.lastIndexOf(logsuffix) != -1)
      {
            ParseLog(afile.Name);
      }
      eFiles.moveNext();
}

errorfile.WriteLine("---- End ------");
errorfile.Close();
WSHShell.run("maillog.cmd", 1, true);


function ParseLog(filename)
{
      logfile = oFSO.OpenTextFile(sLogDir + filename);
      while(!logfile.AtEndOfStream)
      {
            line = logfile.ReadLine();
            arr = reFileSum.exec(" ");
            arr = reFileSum.exec(line);
            if(arr != null)
            {
                  //if((arr[1] != 0) || (arr[2] != 0))
                        errorfile.WriteLine("\r(" + filename + ")Files - Mismatch: " + arr[1] + ", Failed: " + arr[2]);
            }
            arr = reDirSum.exec(" ");
            arr = reDirSum.exec(line);
            if(arr != null)
            {
                  //if((arr[1] != 0) || (arr[2] != 0))
                        errorfile.WriteLine("\r\n(" + filename + ")Dirs - Mismatch: " + arr[1] + ", Failed: " + arr[2]);
            }
      }
      logfile.Close();            
}

CODE2
oFSO = new ActiveXObject("Scripting.FileSystemObject");
oDate = new Date();
iCurrentTime = oDate.valueOf();
MsecInDay = 1000 * 60 * 60 * 24;

sLogDir = "c:\\admin\\logs\\";
sHomeDir = "c:\\admin\\scripts\\";
aDays = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");


oLogFolder = oFSO.GetFolder(sLogDir);
eFiles = new Enumerator(oLogFolder.Files);
while(!eFiles.atEnd())
{
      afile = eFiles.item();
      if(afile.Name.lastIndexOf(".txt") != -1)
      {
            iFileModTime = Date.parse(afile.DateLastModified);
            iAgeDays = Math.round((iCurrentTime - iFileModTime) / MsecInDay);
            if( iAgeDays > 14)
                  oFSO.DeleteFile(sLogDir + afile.Name, true);
      }
      eFiles.moveNext();
}

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros