nchernoff
2008-06-03, 15:44
Migrated From JP Software Wiki
This example shows how a batch file can create an HTML document with a set of system
status information generated by 4NT commands. It's less than 25 lines long!
Consider adding a few simple additions to create a complete system:
Get the system name and append it to the file name creating a unique page for each system
Put this code in a loop to execute every 5 minutes, creating a fresh page
Add an FTP upload of the page to a central website to group it with other server generated status pages
With about 30 lines of code, you can produce a monitoring application you can load on each of your Windows servers.
<pre>
type <<- EndHTML >! status.html
<html>
<head>
<title>Server Status</title>
</head>
<body>
<h1>Server Status</h1>
<p>
Total memory: %@comma[%@winmemory[5]] bytes<br>
Memory available: %@comma[%@winmemory[6]] bytes<br>
Memory load: %@winmemory[0] %%</p>
<p>
Free disk space on drive C: %@diskfree[c:,Mc] MB<br>
Free disk space on drive D: %@diskfree[d:,Mc] MB</p>
<p>
Total users: %users<br>
Users connected: %connected</p>
<p>
Reported generated %_isodate %_time by
%@upper[%@filename[%_batchname]].</p>
</body>
</html>
</pre>
endHTML
"Here-document" (http://www.jpsoft.com/help/index.htm?redirection.htm) provides an easy way to embed an entire HTML document in your batch file.
Variables and functions in the "here-document" text will be expanded, allowing you to easily insert information into the HTML framework. (Remember to double any literal percent signs!)
In this example, the <code>[http://www.jpsoft.com/help/index.htm?type.htm TYPE]</code> command reads redirected input (an undocumented feature), which is then redirected into the output file <code>status.html</code>. This approach can also be used with other text markup languages, such as XML and RTF.
This example shows how a batch file can create an HTML document with a set of system
status information generated by 4NT commands. It's less than 25 lines long!
Consider adding a few simple additions to create a complete system:
Get the system name and append it to the file name creating a unique page for each system
Put this code in a loop to execute every 5 minutes, creating a fresh page
Add an FTP upload of the page to a central website to group it with other server generated status pages
With about 30 lines of code, you can produce a monitoring application you can load on each of your Windows servers.
<pre>
type <<- EndHTML >! status.html
<html>
<head>
<title>Server Status</title>
</head>
<body>
<h1>Server Status</h1>
<p>
Total memory: %@comma[%@winmemory[5]] bytes<br>
Memory available: %@comma[%@winmemory[6]] bytes<br>
Memory load: %@winmemory[0] %%</p>
<p>
Free disk space on drive C: %@diskfree[c:,Mc] MB<br>
Free disk space on drive D: %@diskfree[d:,Mc] MB</p>
<p>
Total users: %users<br>
Users connected: %connected</p>
<p>
Reported generated %_isodate %_time by
%@upper[%@filename[%_batchname]].</p>
</body>
</html>
</pre>
endHTML
"Here-document" (http://www.jpsoft.com/help/index.htm?redirection.htm) provides an easy way to embed an entire HTML document in your batch file.
Variables and functions in the "here-document" text will be expanded, allowing you to easily insert information into the HTML framework. (Remember to double any literal percent signs!)
In this example, the <code>[http://www.jpsoft.com/help/index.htm?type.htm TYPE]</code> command reads redirected input (an undocumented feature), which is then redirected into the output file <code>status.html</code>. This approach can also be used with other text markup languages, such as XML and RTF.