Tip

HTML from DOS batch

This tip was submitted to the SearchWin2000.com tip exchange by member Mac McNeil. Please let other users know how useful it is by rating it below.


Do you have any DOS batch jobs that run on a regular basis, maybe for server monitoring or performing housekeeping duties? Do you need to know the realtime status of jobs when they've completed or, even better, while they're still running? Sure you do!

The standard method of accomplishing this would be to redirect an ECHO command to a file that contains the status, as in:

    Requires Free Membership to View

ECHO job finished with no errors at %date% %time% >> Status.txt

Wouldn't it be useful if you could view such a status on a Web page? Well, you can. Instead of echoing plain text to an output file, echo HTML code which can be loaded into a Web page on the fly. All you need to know is a few tips and tricks:

  • Remember that ECHO some text >status.htm initiates the output file and ECHO some text >>status.htm appends to it on a new line.

  • Generate a dummy page in your favorite HTML editor to get the look you want, then study the generated HTML code. That's what you want to replicate using the ECHO command in DOS batch.

    o Use three files -- a header, a footer and the data -- and then combine them when the final HTML file is to be created. This allows simple creation of color schemes, text formatting, etc.

  • To generate a > or a <, precede the charater with a carat as in ^> echo ^<p^>^<font face="Comic Sans MS" size="3"^>No errors detected since the job started.^</font^>^</p^> >>status.htm

  • The tilde character truncates output as in %date:~0,9% %time:~0,5% truncates to "ddd dd/mm hh:mm."

    When specifying a percentage as in <td width="33%">, you must enter two %% -- e.g. ^<td width="33%%"^>

    Example code

    
    set weblog = "c:datastatus.htm"
    set bggrn="#00FF00"
    set txtgrn="#000080"
    
    :: totcount, failcount and servcount are incremented elsewhere in the code
    
    echo ^<html^> >%weblog%
    echo ^<head^> >>%weblog%
    echo ^<meta http-equiv="refresh" content="15"^> >>%weblog%
    echo ^<title^>Final Status^</title^> >>%weblog%
    echo ^</head^> >>%weblog%
    echo ^<body bgcolor=%bggrn% text=%txtgrn%^> >>%weblog%
    echo ^<p^>^<font face="Comic Sans MS" size="3"^>No incidents
    detected on the most recent pass of job ^<u^>%webname%^</u^>^</font^>^<br^> >>%weblog%
    echo ^<font face="Comic Sans MS" size="2"^>Checked %servcount% 
    
    Servers in this pass which completed on: %date% at %time%.^<br^> >>%
    weblog% 
    echo 
    
    Since %sdate% at %stime% we have checked %totcount% servers and detected %
    failcount% failures.^</font^>^</p^> >>%weblog% 
    
    echo ^</body^> >>%weblog% 
    echo ^</html^> >>%weblog%
    

    This was first published in April 2003

  • There are Comments. Add yours.

     
    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.