var oShell = new ActiveXObject("WScript.Shell"); //var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var unicodefile = oShell.ExpandEnvironmentStrings("%TMP%" + "\\" + "unicodefile"); var asciifile = oShell.ExpandEnvironmentStrings("%TMP%" + "\\" + "asciifile"); function getdatestr () { // Create a date object and assign variable to date components. // var oDate = new Date(); var year = oDate.getFullYear(); var mon = oDate.getMonth() + 1; var day = oDate.getDate(); var hour = oDate.getHours(); var min = oDate.getMinutes(); var sec = oDate.getSeconds(); // // Any single position date components need to prefixed with zeros. // mon = (mon < 10)? "0" + mon : mon; day = (day < 10)? "0" + day : day; hour = (hour < 10)? "0" + hour : hour; min = (min < 10)? "0" + min : min; sec = (sec < 10)? "0" + sec : sec; return (year + mon + day + hour + min + sec); } function logmessage(msg) { WScript.Stdout.Write(msg); } function gethostname() { var oShell = new ActiveXObject("WScript.Shell"); return (oShell.ExpandEnvironmentStrings("%COMPUTERNAME%")); } function makedir (dirpath) { var oShell = new ActiveXObject("WScript.Shell") var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var parentpath = oFSO.GetParentFolderName(dirpath); // Create the parent folder if it doesn't exist // if (!oFSO.FolderExists(parentpath)) // { // makedir(parentpath); // } if (!oFSO.FolderExists(dirpath)) { oFSO.CreateFolder(dirpath); } } function createfile(workingdir, filename) { var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var outfile = oFSO.GetFolder(".") + "\\" + workingdir + "\\" + filename; oFSO.CreateTextFile(outfile); return outfile; } function writefile(filename, str) { ForAppending = 8; var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var outfile = oFSO.OpenTextFile(filename, ForAppending, false); outfile.WriteLine(str); outfile.Close(); } function runanalysis() { var oExec = oShell.exec("%COMSPEC%" + "\\..\\dllcache\\msinfo32.exe" + " /categories /report " + unicodefile); if (oExec.ProcessID == 0 && oExec.Status == 1) { logmessage("oShell.exec failed.\n"); } // Wait until command is completed before continuing. logmessage("running analysis"); while (oExec.Status == 0) { logmessage("."); WScript.Sleep(1000); } } function convertformat() { var oExec = oShell.run("%COMSPEC% /C" + " type " + unicodefile + ">" + asciifile, 0 ); if (oExec.ProcessID == 0 && oExec.Status == 1) { logmessage("oShell.exec failed.\n"); } // Wait until command is completed before continuing. logmessage("Converting output to asciii"); while (oExec.Status == 0) { logmessage("."); WScript.Sleep(1000); } } function parseoutput(target) { var forReading = 1, forWriting = 2, forAppending = 8; // open the logfile var fs = new ActiveXObject("Scripting.FileSystemObject"); var f = fs.GetFile(asciifile); is = f.OpenAsTextStream( forReading, 0 ); // var inputlog = oFSO.OpenTextFile(asciifile, 1); //var beginexpr = new RegExp("\[System Summary\]"); var beginexpr = new RegExp("[\[]" + target + "[\]]"); var endexpr = new RegExp(/^\[/); start = 0; while (!is.AtEndOfStream) { line = is.ReadLine(); if (endexpr.test(line) && start == 1) { start = 0; break; } if (beginexpr.test(line)) { start = 1; } if (start == 1) { logmessage (line + "\n"); } } is.Close(); } datetime = getdatestr(); version = "3.4"; hostname = gethostname(); workingdir = hostname; makedir(workingdir); f = createfile(workingdir, "index.html"); indexstr = "<html><head><title>" + workingdir + ": Snapshot report</title></head>\n" + "<iframe src=heading.html height=\"20%\" width=\"100%\" name=\"head_frame\"></iframe>\n" + "<iframe src=Summary.html height=\"80%\" width=\"100%\" name=\"info_frame\"></iframe>\n" + "<html>\n"; writefile(f, indexstr); f = createfile(workingdir, "heading.html"); headerstr = "<html><head><title>Report Generated for HP Support</title><base target=\"info_frame\"></head>" + "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#990200\" vlink=\"#006342\">" + "<b><center>Report for " + hostname + " on " + datetime + "</Center></b>" + "<b><center>Produced by snapshot Version " + version + "</Center></b>" + "<center><table wdith=\"90%\" cellpadding=5>" + "<tr>" + "<td><a href=Summary.html>Summary</a></td>" + "<td><a href=Kernel.html>Kernel</a></td>" + "<td><a href=Hardware.html>Hardware</a></td>" + "<td><a href=Software.html>Software</a></td>" + "<td><a href=File-Systems.html>File Systems</a></td>" + "<td><a href=Network.html>Network</a></td>" + "<td><a href=Services.html>Services</a></td>" + "<td><a href=Stats.html>Stats</a></td>" + "<td><a href=Log-Files.html>Log-Files</a></td>" + "<td><a href=Misc-Files.html>Misc-files</a></td>" + "<td><a href=Graphics.html>Graphics</a></td>" + "</tr>" + "</table>" + "</center>" + "</body>" + "</html>"; writefile(f, headerstr); //logmessage(hostname); //runanalysis(); //convertformat(); parseoutput("System Summary"); parseoutput("I/O"); parseoutput("Memory"); parseoutput("Storage"); parseoutput("Drives"); parseoutput("Disk"); parseoutput("Summary"); parseoutput("Conflicts/Sharing");
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 10980 | Matt Attaway |
Add helpful script to dump all the info about a Linux server This is an open source script from HP. I'm going to expand it to get Perforce server info. |