/* Collection_main.js v19.1 This script is used to search for all the installed instances of Oracle products in the target system. */ /** * main */ //Set up use of Env variables var WshShell = WScript.CreateObject("WScript.Shell"); var fso = new ActiveXObject("Scripting.FileSystemObject"); var SYSTEM_FOLDER = 1; var TEMP_FOLDER = 2; var wbemFlagReturnImmediately = 0x10; var wbemFlagForwardOnly = 0x20; //Get the Temp folder try { var tfolder = fso.GetSpecialFolder(TEMP_FOLDER); } catch(e) { var tfolder = fso.getFolder(".").path +"\\temp"; } //declare and initialize vars // Script descrptive vars var SCRIPT_VERSION = "19.1" var CT_BUILD_VERSION = "19.1" var SCRIPT_NAME = "Collection_main.js" var SCRIPT_OPTIONS = WScript.Arguments; //CT vars var MACHINE_NAME = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%"); var CT_HOME = fso.getFolder(".").path; var CT_PID = get_pid(); var CT_TMP = tfolder + "\\ct_tmp_" + MACHINE_NAME + "_" + CT_PID + "\\"; var OUTPUT_DIR = CT_HOME + "\\output\\"; var CT_DEBUG = "" var SEARCH_DIR = GetDriveList(); var OUTPUT_DEBUG = ""; var DEBUG = false; var LICAGREE = false; var COLLECT_CT_DEBUG = true; var PRODLIST = ""; var FASTSEARCH = false; var REMOTE_DB = ""; var MASK_DATA = ""; var ForReading = 1; var TristateFalse = 0; var ForWriting = 2, ForAppending = 8; var SEARCH_COMMAND = ""; var WARNING_EMPTY = false; var ERRORS_EMPTY = false; //Product File lists and variables var ALLSEARCHFILES = ""; var PRODUCTLIST = ""; var ALLPRODLIST = ""; var RUNLIST = ""; var RUNCPUQ = ""; var RANCPUQ = "false"; var PROCESSLIST = ""; var CMDOUTFILELIST = ""; var COMPLETEPRODLIST = ""; var BUNDLEFILES=""; var TSFILES=""; var TAILFILES=""; var LISTINGFILES=""; var COPYFILES=""; var LOGFILES=""; var CT_HOMES=""; var CT_HOMES_arr=""; var PRODUCTSRUN=""; var COLLECTRMDATAFILES=""; //debug and error files var CT_DEBUG_FILE_fname = ""; var CT_DEBUG_FILE = ""; // check the command line arguements. checkArguments(SCRIPT_OPTIONS); try { createDirectoryFromPath(CT_TMP); } catch (exception) { WINDOWSCMDERR.WriteLine("The directory " + CT_TMP + " can not be created. Exception:" + exception); } if ( !fso.FolderExists(CT_TMP + "logs\\") ) { try { createDirectoryFromPath(CT_TMP + "logs\\"); } catch (exception) { echo_logs("CT: CT-00110: WARNING: The directory " + CT_TMP + "logs\\ does not exist and can not be created.","Warnings"); } } WScript.echo(CT_TMP + "logs\\"); CT_DEBUG = CT_TMP + "\\debug\\"; try { createDirectoryFromPath(CT_DEBUG); } catch (exception) { WINDOWSCMDERR.WriteLine("The directory " + CT_DEBUG + " can not be created. Exception:" + exception); } if ( DEBUG ) debugWarning(); credentialValidation(); // print license if customer doesn't use -L Y if ( !LICAGREE ) { runCommand("more ..\\resources\\util\\license_agreement.txt && pause", 1); WScript.StdOut.Write("\n\n Do you accept the license agreement (y|n)"); var ANSWER = WScript.StdIn.ReadLine(); var licAgreeLoop = true; while ( licAgreeLoop ) { switch ( ANSWER ) { case "Y" : case "y" : licAgreeLoop = false; break; case "n" : case "N" : printArgUsage(); echo_logs("CT: CT-00102: WARNING: You must accept the license agreement to continue.","Warnings"); licAgreeLoop = false; WScript.Quit(1); break; default : WScript.StdOut.Write("Invalid option, please use y or n. Do you accept the license agreement (y|n)"); ANSWER = WScript.StdIn.ReadLine(); } } } var OUTPUT_DIR_FSO = fso.getFolder(OUTPUT_DIR); var CT_FILES_fname = CT_TMP + "logs\\CTfiles.txt"; //var CT_FILES = fso.OpenTextFile(CT_FILES_fname, ForWriting, "True"); var CT_SORTED_FILES_fname = CT_TMP + "logs\\CTsortedfiles.txt"; //var CT_SORTED_FILES = fso.OpenTextFile(CT_SORTED_FILES_fname, ForWriting, "True"); var CT_MACHINFO_FILE_fname = CT_TMP + "logs\\" + MACHINE_NAME + "-info.txt"; var CT_MACHINFO_FILE = fso.OpenTextFile(CT_MACHINFO_FILE_fname, ForWriting, "True"); var CT_LOGS_FILE_fname = CT_TMP + "logs\\CTlogfiles.txt"; var CT_LOGS_FILE = fso.OpenTextFile(CT_LOGS_FILE_fname, ForWriting, "True"); var CMDFILE_fname = CT_TMP + "logs\\OraCmdList.txt"; var CMDFILE = fso.OpenTextFile(CMDFILE_fname, ForWriting, "True"); var CMDOUTFILE_fname = CT_TMP + "logs\\OraCmdOutFileList.txt"; var CMDOUTFILE = fso.OpenTextFile(CMDOUTFILE_fname, ForWriting, "True"); var WINDOWSCMDERR_fname = CT_TMP + "logs\\windowscmderrs.txt"; var WINDOWSCMDERR = fso.OpenTextFile(WINDOWSCMDERR_fname, ForWriting, "True"); // results file var CT_RESULTS_FILE_fname = CT_TMP + "logs\\Collection-" + MACHINE_NAME + ".txt"; var CT_RESULTS_FILE = fso.OpenTextFile(CT_RESULTS_FILE_fname, ForWriting, "True"); var CT_ACTIONS_RESULTS_FILE_fname = CT_TMP + "logs\\Collection-Actions-" + MACHINE_NAME + ".txt"; var CT_ACTIONS_RESULTS_FILE = fso.OpenTextFile(CT_ACTIONS_RESULTS_FILE_fname, ForWriting, "True"); var CT_COLLECTED_FILE_fname = CT_TMP + "logs\\CT_collected.log"; var CT_COLLECTED_FILE = fso.OpenTextFile(CT_COLLECTED_FILE_fname, ForWriting, "True"); var CT_WARNINGS_FILE_fname = CT_TMP + "logs\\CT_warnings.log"; var CT_WARNINGS_FILE = fso.OpenTextFile(CT_WARNINGS_FILE_fname, ForWriting, "True"); var CT_ERRORS_FILE_fname = CT_TMP + "logs\\CT_errors.log"; var CT_ERRORS_FILE = fso.OpenTextFile(CT_ERRORS_FILE_fname, ForWriting, "True"); var CT_HOMES_FILE_fname = CT_TMP + "logs\\Collection-" + MACHINE_NAME + "-CT_Homes.txt"; var CT_HOMES_FILE = fso.OpenTextFile(CT_HOMES_FILE_fname, ForWriting, "True"); var CT_RESULTS_SUMMARY_FILE_fname = CT_TMP + "logs\\results_summary.log"; var CT_RESULTS_SUMMARY_FILE = fso.OpenTextFile(CT_RESULTS_SUMMARY_FILE_fname, ForWriting, "True"); PRODLIST = PRODLIST.slice(0,-1); var scriptOptions = ""; for (var ii = 0; ii < SCRIPT_OPTIONS.length; ii++) scriptOptions += SCRIPT_OPTIONS(ii) + " "; // get the Products to be searched for try { getProducts(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during getProducts function processing. Exception "+ e.description); } //parse and set search files and process list try { parseProductFiles(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during parseProductFiles function processing. Exception "+ e.description); } // export the output dir for child process only. var wshSystemEnv = WshShell.Environment( "PROCESS" ); wshSystemEnv("OUTPUT_DIR") = OUTPUT_DIR; wshSystemEnv("PRODLIST") = PRODLIST; wshSystemEnv("ALLPRODLIST") = ALLPRODLIST; wshSystemEnv("PRODUCTLIST") = PRODUCTLIST; wshSystemEnv("LICAGREE") = LICAGREE; wshSystemEnv("SCRIPT_OPTIONS") = scriptOptions; wshSystemEnv("REMOTE_DB") = REMOTE_DB; wshSystemEnv("CT_BUILD_VERSION") = CT_BUILD_VERSION; wshSystemEnv("CT_TMP") = CT_TMP; wshSystemEnv("CT_HOME") = CT_HOME; // Run CPUQ before machine info section if ( RUNLIST.indexOf("cpuq_main") != -1 ) { doRunCmd(RUNCPUQ); RANCPUQ = "true"; } //Generate a machine summary file try { printMachineInfo(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during printMachineInfo function processing. Exception "+ e.description); } //Generate a list for fastsearch option if ( ALLPRODLIST.indexOf("WLS") != -1 ) { try { getDefaultOracleEnv(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during getDefaultOracleEnv function processing. Exception "+ e.description); } } //search start time var SEARCH_START = new Date(); var SEARCH_FINISH; // find all the files on the target system; skip search if there are no search files if ( ALLSEARCHFILES != "" ) { try { doSearch(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during doSearch function processing. Exception "+ e.description); } SEARCH_FINISH = new Date(); WScript.echo("CT file search started at " + SEARCH_START + "and finished at " +SEARCH_FINISH); } else { SEARCH_FINISH = new Date(); } //# print search information CT_MACHINFO_FILE.WriteLine("[BEGIN SEARCH INFO]"); CT_MACHINFO_FILE.WriteLine("Search start=" + SEARCH_START); CT_MACHINFO_FILE.WriteLine("Search command=" + SEARCH_COMMAND); CT_MACHINFO_FILE.WriteLine("Search finish=" + SEARCH_FINISH); CT_MACHINFO_FILE.WriteLine("[END SEARCH INFO]"); // Run the specified Commands or scripts try { doRunCmd(RUNLIST); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during doRunCmd(RUNLIST) function processing. Exception "+ e.description); } // Clean up the file list get rid of non Oracle config.xml and registry.xml try { fileGetCTFiles(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during fileGetCTFiles function processing. Exception "+ e.description); } // package CT_SORTED_FILES results for post-processing try { fileAction(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during fileAction function processing. Exception "+ e.description); } try { //Add the WLST "compare_result.txt" file to the zip if ( fso.FileExists("compare_result.txt") ) fso.CopyFile("compare_result.txt", CT_TMP + "logs\\compare_result.txt"); } catch (exception) { echo_logs("CT: CT-00125: WARNING: Error copying output files. Exception: " + exception.description,"Warnings"); } //Generate a list of FMWHomes collected if ( ALLPRODLIST.indexOf("WLS") != -1 ) { try { getDefaultOracleEnv(); } catch(e) { } } //Generate a list of config locations collected if ( ALLPRODLIST.indexOf("WLS") != -1 ) { try { configsCollected(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during configsCollected function processing. Exception "+ e.description); } } //close the file objects and delete the files. CT_MACHINFO_FILE.Close(); CT_LOGS_FILE.Close(); CMDFILE.Close(); CMDOUTFILE.Close(); CT_DEBUG_FILE.Close(); CT_RESULTS_FILE.Close(); CT_ACTIONS_RESULTS_FILE.Close(); //mask data if required. if ( MASK_DATA == "all" || MASK_DATA == "IP" || MASK_DATA == "ip" || MASK_DATA == "user" ) { WScript.Echo("\nMasking sensitive data ...........\n"); try { maskResults(); } catch(e) { echo_logs("CT: CT-00120: WARNING: Exception during maskResults function processing. Exception "+ e.description,"Warnings"); } } //Clear screen before last messages WScript.Echo("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); //print output to screen try { printResults(); } catch(e) { WINDOWSCMDERR.WriteLine("Exception during printResults function processing. Exception "+ e.description); } // close and delete unecessary logs files CT_ERRORS_FILE.Close(); CT_COLLECTED_FILE.Close(); CT_WARNINGS_FILE.Close(); CT_HOMES_FILE.Close(); CT_RESULTS_SUMMARY_FILE.Close(); WINDOWSCMDERR.Close(); // mv files to debug try { debugFiles = ShowFiles(CT_TMP + "logs\\"); } catch (e) { WScript.Echo("CT: CT-00122: WARNING: Exception during listing of debug files. Exception "+ e.description); } // loop through each of the files in the folder for (; !debugFiles.atEnd(); debugFiles.moveNext()) { fname = debugFiles.item(); shortFname = fso.GetBaseName(fname); extFname = fso.GetExtensionName(fname); if ( ALLPRODLIST.indexOf("WLS") != -1 || ALLPRODLIST.indexOf("OAS") != -1 || ALLPRODLIST.indexOf("Tuxedo") != -1 || ALLPRODLIST.indexOf("OBI") != 1 ) { if ( shortFname != "db_list" && fname != CT_RESULTS_FILE_fname && fname != CT_MACHINFO_FILE_fname && fname != CT_LOGS_FILE_fname ) { try { fso.MoveFile(fname,CT_DEBUG + "\\" + shortFname + "." + extFname); } catch (e) { WScript.Echo("CT: CT-00124: WARNING: Exception during moving of debug files. Exception "+ e.description); } } } else { if ( shortFname != "db_list" ) { try { fso.MoveFile(fname,CT_DEBUG + "\\" + shortFname + "." + extFname); } catch (e) { WScript.Echo("CT: CT-00124: WARNING: Exception during moving of debug files. Exception "+ e.description); } } } } var currentdate = new Date(); var ZIPTIMESTAMP ="." + currentdate.getFullYear() + (currentdate.getMonth()+1) + currentdate.getDate() + "_" + currentdate.getHours() + currentdate.getMinutes() + currentdate.getSeconds(); //Compress the debug files if ( COLLECT_CT_DEBUG ) { try { zipDebug(); } catch(e) { WScript.Echo("CT: CT-00123: WARNING: Exception during zipDebug function processing. Exception "+ e.description); } } if ( PRODLIST === "CPUQ," ) { try { fso.DeleteFolder(CT_TMP + "logs"); } catch (e) { } } //Compress the Results file try { zipFiles(); } catch(e) { WScript.Echo("CT: CT-00121: WARNING: Exception during zipFiles function processing. Exception "+ e.description); } if ( fso.FileExists("compare_result.txt") ) { fso.DeleteFile("compare_result.txt"); } if ( fso.FolderExists(CT_TMP) ) { try { fso.DeleteFolder(CT_TMP.slice(0,-1)); } catch (e) { } } //destroy the FSO object fso = null; /*############################ End MAIN ############################*/ /* ********************User Command Line Management Utilities********************* */ /** * function to print the command line options syntax */ function printArgUsage() { var argUsage = new Array (); argUsage = ["-d search_dir [-p product] [-o full_path_dir_name] [-debug true|false] [-m all|ip|user]", " [-L Y|y|N|n] [-fastsearch] [-tns] [-t full_path_dir_name] \n", "-d Specifiy the directories to be searched for the installations.", " A quoted string of directory names separated by a comma is required for", " when more than 1 directory is to be searched. The default is all fixed ", " or local drives. i.e. c:\,d:\ and not the CDROM or NFS drives.\n", "-o Option to output the collected files to the directory", " given by . The option should be a full path name.", " It will be named Collection-.zip.", " If not specified, default is the output directory where the tool is located.\n", "-debug [true|false] Option to turn on debugging information. Default is false.\n", "-m Option to turn on masking of sensitive information.", " Perl needs to be in the system path for this to run. Default is off.", " It can mask username/password combinations or IP addressess, ", " see README.txt for details.\n", "-L Option to agree to license agreement without having it displayed.", " Default is off, the License Agreement will be printed to the screen.\n", " ***USE OF THIS OPTION IMPLIES LICENSE ACCEPTENCE.***\n", "-p Option to pass in a list of Oracle products to look for.", " valid options include:", " all,FormsReports,OAS,WLS,SOA,Tuxedo,CPUQQ,DB,EBS,", " WLSNUP,WLSBasic,OBI,Webcenter\n", "-fastsearch Option to auto detect Oracle product directories on the system.", " Note: The fast search option of Collection Tool is intended to", " gather information from the system with minimal file searching.\n", "-tns Option to switch from the automatic local database connection", " mode (the default) to an interactive remote database connection", " mode, via database listener. The tool prompts for connection", " description details (e.g. listener host, port, etc), database", " user and password, then connects to the remote database using ", " SQL*Plus and collects the data for the selected products", " DB, EBS). Multiple databases can be collected.", " This mode cannot be used together with the silent mode (-L Y).\n", "-t Option to set the Collection Tool temporary output to files in the", " directory specified by full_path_dir_name. The option should", " be a full pathname. The files will be deleted at the end of the CT", " run. If not specified default is the Windows %TMP% directory.\n"]; for (var ii=0;ii= 0 ) { searchDirs = SEARCH_DIR.split(','); for (var jj=0; jj 0 ) { printArgUsage(); echo_logs("CT: CT-00012: ERROR: Perl was not found in the system path.\nPlease review the documentation for masking requirements.","Errors"); WScript.Quit(1); } else { perlDocsError = runCommand("perldoc -l Digest::SHA", 0 ); if ( perlDocsError > 0 ) { printArgUsage(); echo_logs("CT: CT-00013: ERROR: Cannot find a perl with Digest::SHA installed.\nPlease review the documentation for masking requirements.","Errors"); WScript.Quit(1); } } break; case "-t" : try { CT_TMP = argVals.Item(ii +1); } catch (exception) { printArgUsage(); echo_logs("CT: CT-00017: ERROR: No argument provided to the -t parameter.","Errors"); WScript.Quit(1); } CT_TMP = argVals.Item(ii +1); if ( CT_TMP.charAt(CT_TMP.length-1) != "\\" ) { CT_TMP += "\\"; } CT_TMP = CT_TMP + "ct_tmp_" + MACHINE_NAME + "_" + CT_PID + "\\"; if ( !fso.FolderExists(CT_TMP) ) { if(!CT_TMP.charAt(0).match(/^[a-zA-Z]/)) { printArgUsage(); echo_logs("CT: CT-00028: ERROR: Output directory: " + CT_TMP + ", is not a valid Windows Full path name.","Errors"); WScript.Echo(); WScript.Quit(1); } else if(!CT_TMP.charAt(1).match(/^[:]/) || !CT_TMP.charAt(2).match(/^[\/\\]/)) { printArgUsage(); echo_logs("CT: CT-00028: ERROR: Output directory: " + CT_TMP + ", is not a valid Windows Full path name.","Errors"); WScript.Quit(1); } else { try { createDirectoryFromPath(CT_TMP); } catch (exception) { printArgUsage(); echo_logs("CT: CT-00029: ERROR: The directory " + CT_TMP + " does not exist and can not be created.\n Please chose a different directory or create it outside of Collection Tool.","Errors"); WScript.Quit(1); } } } break; default : printArgUsage(); echo_logs("CT: CT-00015: ERROR: " + argVals.Item(ii) + " is an invalid entry.","Errors"); WScript.Quit(1); } } } if ( REMOTE_DB == "YES" && LICAGREE ) { printArgUsage(); echo_logs("CT: CT-00016: ERROR: -tns option cannot be used together with silent mode (-L Y)","Errors"); WScript.Quit(1); } if ( !fso.FolderExists(OUTPUT_DIR) ) { try { createDirectoryFromPath(OUTPUT_DIR); } catch (exception) { echo_logs("CT: CT-00109: WARNING: The directory " + OUTPUT_DIR + "\\output\\ does not exist and can not be created.","Warnings"); } } if ( PRODLIST.indexOf("all") != -1 || PRODLIST.indexOf("WLS,") != -1 || PRODLIST.indexOf("FMW") != -1 || PRODLIST.indexOf("OAS") != -1 ) { try { createDirectoryFromPath(CT_TMP + "FMW\\"); } catch (exception) { echo_logs("CT: CT-00109: WARNING: The directory " + CT_TMP + "FMW\\ does not exist and can not be created.","Warnings"); } } if ( !fso.FolderExists(CT_TMP + "logs\\") ) { try { createDirectoryFromPath(CT_TMP + "logs\\"); } catch (exception) { echo_logs("CT: CT-00110: WARNING: The directory " + CT_TMP + "logs\\ does not exist and can not be created.","Warnings"); } } CT_DEBUG = CT_TMP + "debug\\"; if ( !fso.FolderExists( CT_DEBUG ) ) { try { createDirectoryFromPath( CT_DEBUG ); } catch (exception) { echo_logs("CT: CT-00111: WARNING: The directory " + CT_DEBUG + " does not exist and can not be created.","Warnings"); } } //debug and error files CT_DEBUG_FILE_fname = CT_TMP + "logs\\CTdebugfile.txt"; CT_DEBUG_FILE = fso.OpenTextFile(CT_DEBUG_FILE_fname, ForWriting, "True"); //debug var options = ""; if ( DEBUG ) { echo_debug("debug.function.checkSyntax"); for (var ii = 0; ii < SCRIPT_OPTIONS.length; ii++) options += SCRIPT_OPTIONS(ii) + " "; echo_debug("debug.script options=" + options); echo_debug("MACHINE_NAME =" + MACHINE_NAME); echo_debug("OUTPUT_DIR =" + OUTPUT_DIR ); echo_debug("SEARCH_DIR =" + SEARCH_DIR ); echo_debug("OUTPUT_DEBUG =" + OUTPUT_DEBUG ); echo_debug("LICAGREE =" + LICAGREE ); echo_debug("PRODLIST =" + PRODLIST ); echo_debug("MASK_DATA =" + MASK_DATA ); echo_debug("\nCT_DEBUG_FILE_fname==" + CT_DEBUG_FILE_fname); } } /** * function to check if the current user is an administrator. */ function credentialValidation() { var credentials = runCommand("net session >nul 2>&1",0); if ( credentials != 0 ) { echo_logs("CT: CT-00100: WARNING: Current OS user does NOT have 'administrative' rights!\nIf you're sure that the Current OS user is granted the required privileges, continue with yes(y), otherwise select No(n) and please log on with a OS user with sufficient privileges.\nRunning the Collection Tool with insufficient privileges may have a significant impact on the quality of the data and information collected from this environment. Due to this, Oracle may have to get back to you and ask for additional items, or to execute again.","Warnings"); if ( !LICAGREE ) { WScript.StdOut.Write("\n\n Please choose an Y to continue or N to quit:"); var ANSWER = WScript.StdIn.ReadLine(); var licAgreeLoop = true; while ( licAgreeLoop ) { switch ( ANSWER ) { case "Y" : case "y" : licAgreeLoop = false; break; case "n" : case "N" : echo_logs("CT: CT-00101: WARNING: \nUser chose not to continue the Collection Tool.","Warnings"); licAgreeLoop = false; WScript.Quit(1); break; default : WScript.StdOut.Write("Invalid option, please use y or n. (y|n)"); ANSWER = WScript.StdIn.ReadLine(); } } } } } /** * function to check if the user understands the debug risk. */ function debugWarning() { echo_logs("CT: CT-00200: WARNING: You have chosen to run the Collection Tool in debug mode.\n The script will write data in files in order for Oracle to debug the running of the scripts. You are required to inspect the files for any data that may be sensitive before returning the output to Oracle. \nIf you wish to continue, continue with yes(y), otherwise select no(n) and contact your assigned consultant for more details.","Warnings"); WScript.StdOut.Write("\n\n Please choose an Y to continue or N to quit:"); var ANSWER = WScript.StdIn.ReadLine(); var licAgreeLoop = true; while ( licAgreeLoop ) { switch ( ANSWER ) { case "Y" : case "y" : licAgreeLoop = false; break; case "n" : case "N" : echo_logs("CT: CT-00101: WARNING: \nUser chose not to continue the Collection Tool.","Warnings"); licAgreeLoop = false; WScript.Quit(1); break; default : WScript.StdOut.Write("Invalid option, please use y or n. (y|n)"); ANSWER = WScript.StdIn.ReadLine(); } } } /** ################################################################################ # #***********************Helper and Debug Functions************************ # ################################################################################ */ /** * get_pid - get the pid of the cscript running this. */ function get_pid() { var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2"); var pidItems = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'cscript.exe'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); var pid; try { var enumItems = new Enumerator(pidItems); for (; !enumItems.atEnd(); enumItems.moveNext()) { var objItem = enumItems.item(); if ( objItem.CommandLine.indexOf("Collection_main.js") > -1 ) pid = objItem.ProcessID; } } catch(e) { pid = 0000; if( DEBUG ) echo_debug("OBJItem error==" + e.description); } return pid; } /** * echo_debug - enhace debugging */ function echo_debug(args) { WScript.Echo(args); try { CT_DEBUG_FILE.WriteLine(args); } catch(e) { } } /** * echo_logs - enhace debugging */ function echo_logs(loggingText,loggingFile) { WScript.Echo(loggingText); try { if ( loggingFile.indexOf("Collected") != -1 ) { CT_COLLECTED_FILE.WriteLine(loggingText); } else if ( loggingFile.indexOf("Warnings") != -1 ) { CT_WARNINGS_FILE.WriteLine(loggingText); } else if( loggingFile.indexOf("Errors") != -1 ) { CT_ERRORS_FILE.WriteLine(loggingText); } else if( loggingFile.indexOf("WindowsCMD") != -1 ) { WINDOWSCMDERR.WriteLine(loggingText); } } catch(e) { } } /** * GetAllDriveList - function to get all of drives on the system. */ function GetAllDriveList() { //Initialize variables var list = new Array(); var dEnum, driveItem; dEnum = new Enumerator(fso.Drives); for (; !dEnum.atEnd(); dEnum.moveNext()) { driveItem = dEnum.item(); switch ( driveItem.DriveType ) { case 0 : list.push(driveItem.Path+ "\\ , DriveType: Unknown"); break; case 1 : list.push(driveItem.Path+ "\\ , DriveType: Removable Drive"); break; case 2 : list.push(driveItem.Path+ "\\ , DriveType: Fixed Disk"); break; case 3 : list.push(driveItem.Path+ "\\ , DriveType: Remote Disk"); break; case 4 : list.push(driveItem.Path+ "\\ , DriveType: CDROM Drive"); break; case 5 : list.push(driveItem.Path+ "\\ , DriveType: RAM Disk"); break; default : list.push(driveItem.Path+ "\\ , DriveType: Not Found"); } } return(list); } /** * GetDriveList - function to get all of the local/fixed drives on the system. */ function GetDriveList() { //Initialize variables var list, dEnum, driveItem; dEnum = new Enumerator(fso.Drives); list = ""; for (; !dEnum.atEnd(); dEnum.moveNext()) { driveItem = dEnum.item(); if (driveItem.DriveType == 2) list = list + driveItem.Path+ "\\," ; } return(list.slice(0,-1)); } /** * ShowFolders - function to return a comma separated list of the folders in a directory. */ function ShowFolders(folderName) { var fs, f, fc, s, dir; s = ""; dir = ""; f = fso.GetFolder(folderName); fc = new Enumerator(f.SubFolders); for (; !fc.atEnd();fc.moveNext()) { s += fso.GetBaseName(fc.item()); s += ","; } return(s); } /** * ShowFiles - function to return collection of the files in a directory. */ function ShowFiles(folderName) { var fs, f, fc, s; s = ""; f = fso.GetFolder(folderName); fc = new Enumerator(f.Files); return(fc); } /** * runCommand - Runs a specific command, uses WindowStyle and waits for the * command to return. * */ function runCommand(theRunCommand,windowStyle) { var cmdLine = "cmd.exe /c " + theRunCommand; var errorCode; if ( theRunCommand.indexOf("dir /a") == -1 ) WScript.Echo("\nRunning ... \n" + cmdLine); errorCode = WshShell.Run(cmdLine, windowStyle, true); return errorCode; } /** * removeCTHOMEDupes * pass in Oracle HOME arrary, truncate it to toplevel dir and remove dupes using the * funcitonality of hashmaps. * */ function removeCTHOMEDupes(CTarr) { var ii; var retArr=[]; var objArr={}; for (var ii=0;ii= 0 ) { WScript.Echo( prodFamilies[ii] ); } } PRODLIST = ""; var ANSWER = ""; while ( ANSWER == "" ) { // Prompt for user value WScript.Echo("\nWhich Product Family would you like to search for?"); ANSWER = WScript.StdIn.ReadLine(); if ( ANSWER == "All" ) { ANSWER = "all"; } //Make sure value is valid if ( ANSWER != "all" && ANSWER.indexOf(",") != -1 ) { var PROD_ARRAY = ANSWER.split(','); for (var jj=0; jj -1 ) objItem.Terminate(); } } catch(e) { if( DEBUG ) echo_debug("OBJItem error==" + e.description); } // Iterate the Drives for (var ii=0; ii> \"" + CT_FILES_fname +"\" && cd /d \""+thisDir +"\"\"",0); SEARCH_COMMAND += "\"cd /d \"" + drive + "\" && dir /a:-d /b /s " + searchFiles + ">> \"" + CT_FILES_fname +"\" && cd /d \""+thisDir +"\"\""; if ( runReturn != 0 ) { echo_logs("Search of " + drive + " returned with error code: " + runReturn ,"WindowsCMD"); } } } /** * doRunCmd() - Parse CMDLIST and run any OS commands or scripts. */ function doRunCmd( cmdsToRun ) { // split the commands lists into an array var cmdList = cmdsToRun.split(","); var runReturn; if ( DEBUG ) WScript.Echo("cmdsToRun=="+cmdsToRun); // loop through each command for (var ii=0; ii= 0 ) { var cmdOutFileColl = ShowFiles(cmdOutBase); // Traverse through the FileCollection using the FOR loop for(; !cmdOutFileColl.atEnd(); cmdOutFileColl.moveNext()) { tmpFile = String(cmdOutFileColl.item()); if ( tmpFile.indexOf(cmdOutFile) != -1 ) { CT_FILES.WriteLine(tmpFile); bundleResults(tmpFile, 0); } } } else { var cmdOutFolderColl = ShowFolders(cmdOutBase).split(','); if ( DEBUG ) echo_debug("cmdOutFolderColl==" + cmdOutFolderColl); for (var jj=0; jj\"" + CT_SORTED_FILES_fname + "\"",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /v /i /g:\"" + fso.getFolder("..").path + "\\resources\\util\\file_sort_list_win.txt\" " + CT_FILES_fname + "\">\"" + CT_SORTED_FILES_fname +"\" returned with error code: " + runReturn ); } if ( DEBUG ) { //WScript.Echo("CT_ONLY_FILES path==" + CT_ONLY_FILES); echo_debug("CT_SORTED_FILES path==" + CT_SORTED_FILES_fname); } /* remove server.xml files that are not Oracle related. */ runReturn = runCommand("findstr /v /i server.xml \"" + CT_SORTED_FILES_fname + "\"> noserverxml.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /v /i server.xml " + CT_SORTED_FILES_fname + "> noserverxml.txt returned with error code: " + runReturn ); } runReturn = runCommand("findstr /i server.xml \"" + CT_SORTED_FILES_fname + "\"> allserverxml.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /i server.xml " + CT_SORTED_FILES_fname + "> allserverxml.txt returned with error code: " + runReturn ); } runReturn = runCommand("findstr /i j2ee allserverxml.txt > j2eeserverxml.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /i j2ee allserverxml.txt > j2eeserverxml.txt returned with error code: " + runReturn ); } runReturn = runCommand("type noserverxml.txt >> j2eeserverxml.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command type noserverxml.txt >> j2eeserverxml.txt returned with error code: " + runReturn ); } runReturn = runCommand("type j2eeserverxml.txt >\"" + CT_SORTED_FILES_fname +"\"",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command type j2eeserverxml.txt >" + CT_SORTED_FILES_fname + " returned with error code: " + runReturn ); } //check for valid config.xml //create a config.xml only list runReturn = runCommand("findstr /i config.xml j2eeserverxml.txt> allconfigs.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /i config.xml j2eeserverxml.txt> allconfigs.txt, returned with error code: " + runReturn ); } //create a sorted list without config.xml runReturn = runCommand("findstr /v /i config.xml j2eeserverxml.txt> noconfigs.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /v /i config.xml j2eeserverxml.txt> noconfigs.txt, returned with error code: " + runReturn ); } //get config.xml files that end with contain tags runReturn = runCommand("findstr /M /i /f:allconfigs.txt \"\" > oracleConfigs.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command findstr /M /i /f:allconfigs.txt \"\" > oracleConfigs.txt returned with error code: " + runReturn ); } //append the noserver.xml list with the j2ee server.xml list runReturn = runCommand("type oracleConfigs.txt >> noconfigs.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command type noserverxml.txt >> noconfigs.txt returned with error code: " + runReturn ); } //create a new CT_SORTED_FILES with the resulting file runReturn = runCommand("type noconfigs.txt >\"" + CT_SORTED_FILES_fname +"\"",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("Command type noconfigs.txt >>" + CT_SORTED_FILES_fname + " returned with error code: " + runReturn ); } // delete temp files fso.DeleteFile("allconfigs.txt"); fso.DeleteFile("noconfigs.txt"); fso.DeleteFile("noserverxml.txt"); fso.DeleteFile("j2eeserverxml.txt"); fso.DeleteFile("allserverxml.txt"); } /*** * fileCopy() - function to copy files to the output dir. */ function fileCopy(fileProcessed, numProccessed) { // debug - Add debug info //WScript.Echo("debug.function.fileCopy"); //WScript.Echo("debug.processing.file"+numProcessed+".copy="+fileProccessed); // obtain timestamp for all copied files fileTimestamp(fileProcessed,numProccessed); CT_RESULTS_FILE.WriteLine("processing.file" + numProccessed + ".copy.data="+fileProcessed); CT_RESULTS_FILE.WriteLine("[COPY_TAG_BEGIN]"); // post command to results file var fCopy = fso.GetFile(fileProcessed); var ts = fCopy.OpenAsTextStream(ForReading, TristateFalse); while (!ts.AtEndOfStream){ CT_RESULTS_FILE.WriteLine(ts.ReadLine()); } CT_RESULTS_FILE.WriteLine("\n[COPY_TAG_END]"); } /*** * fileTail() - function to print the last few lines of a file to the LOGS. */ function fileTail(fileProcessed, numProccessed) { //debug //WScript.Echo("debug.function.fileTail"); //WScript.Echo("debug.processing.file"+numProcessed+".tail="+fileProccessed); CT_LOGS_FILE.WriteLine("processing.file" + numProccessed + ".tail.data="+fileProcessed); CT_LOGS_FILE.WriteLine("[TAIL_TAG_BEGIN]"); var strFile, objFile, arrFileLen, tailStart; var arrFile = new Array (); // open file as a stream, input lines into array objFile = fso.GetFile(fileProcessed); var strFile = objFile.OpenAsTextStream(ForReading, TristateFalse); arrFileLen = 0; while (!strFile.AtEndOfStream){ arrFile[arrFileLen] = strFile.ReadLine(); arrFileLen++; } // if arrFileLen > 20 tail the last 20 lines, else tail the whole file. if ( arrFileLen > 20 ) tailStart = arrFileLen - 20; else tailStart = 0; if ( arrFileLen == 0 ) CT_LOGS_FILE.WriteLine("Log file is empty"); else { for (var ii = tailStart; ii 0 ) { echo_logs("CT: CT-00023: ERROR: Perl error while masking data occured. Please see documentation for troubleshooting instructions." ,"Errors"); MASK_DATA = ""; } } /** * configsCollected() - find the directories where configs where collected. * */ function configsCollected() { var runReturn; var configIndex; var FMW_DOMAINS; var lineconfigs; runReturn = runCommand("findstr \"Zip\" \"" + CT_ACTIONS_RESULTS_FILE_fname + "\" \| findstr \"config.xml\" > configs.txt",0); if ( runReturn != 0 ) { WINDOWSCMDERR.WriteLine("findstr \"Zip\" " + CT_ACTIONS_RESULTS_FILE_fname + " \| findstr \"config.xml\" > configs.txt returned with error code: " + runReturn ); } var ConfigsCollectedRead = fso.OpenTextFile(fso.getFolder(".").path + "\\configs.txt", 1, "True"); try { while (!ConfigsCollectedRead.AtEndOfStream){ lineconfigs = ConfigsCollectedRead.ReadLine(); // Read Data configIndex = lineconfigs.indexOf("\\config\\"); if ( configIndex != -1 ) { FMW_DOMAINS = lineconfigs.substring(7,configIndex); echo_logs("CT: CT-00200: COLLECTED: FMW configuration files for " + FMW_DOMAINS,"Collected"); } } ConfigsCollectedRead.Close(); fso.DeleteFile(fso.getFolder(".").path + "\\configs.txt"); } catch (exception) { } }