Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Australia
    Posts
    2

    Lightbulb Unanswered: XML based output from Unix Shell Script

    I would like to write all the output, including errors of a Shell script I wrote in XML format.

    I noticed there are XML modules for PERL to do this. Are Unix shell scripts capable of creating XML documents, without having to resort to using echo "<tag> ${field} </tag>" ??

    Currently, I have in my Unix shell script, a series of echo commands, carefully placed so that a valid XML document is produced, regardless if the script completes or fails due to an error.

    Here is a sample:

    dump() {
    log "<env>"
    logxml "WORKINGDIR" ${WORKINGDIR}
    logxml "CSVHOME" ${CSVHOME}
    logxml "XMLHOME" ${XMLHOME}
    logxml "OUTPUTHOME" ${OUTPUTHOME}
    logxml "LIBPATH" ${LIBPATH}
    logxml "CLASSPATH" ${CLASSPATH}
    log "</env>"
    }

    where log=echo and logxml is a function which encloses the 2nd parameter in a tag, whose name is the 1st parameter.

    <WORKINGDIR>
    d:/workarea/test
    </WORKINGDIR>

    I manage to produce the log in XML format and it looks great, but the shell script looks ugly. It is riddled with echo commands all over the place.

    Is combining XML and shell script a bad idea? Has someone come up with some sort of solution for this?

  2. #2
    Join Date
    May 2003
    Posts
    10
    sorry, i'm a bit of a newbie with xml and have minimal scripting abilities but, the idea is cool, props if you get the thing working

    -artie

  3. #3
    Join Date
    May 2003
    Location
    Australia
    Posts
    2
    Originally posted by another2
    sorry, i'm a bit of a newbie with xml and have minimal scripting abilities but, the idea is cool, props if you get the thing working

    -artie
    Hi artie,

    Yes, I have got the thing working. But its not as pretty as I would have liked it. Basically it is just wrapping the outputs in tags as I have shown in the example.

    I haven't found any scripting tools which would assist in wrapping output in XML format using Unix Shell scripts.

  4. #4
    Join Date
    Jul 2003
    Location
    Edinburgh
    Posts
    35
    I had to roll my own commands to do something similar. Given an input file of commands to run, I had to catch the stdout, stderr and return value of each command which I then wrapped in XML tags and put in a logfile. Got a very ugly script at the end of it, but also had XML files that more sophisticated programs could work on.

    Whilst shell scripting one-liners can do a lot of work easily, I think trying to build larger applications falls down precisely because there isn't a code repository and modules like CPAN.

    A difficult part was trying to keep program logic seperate from all the echo commands, which you seem to be doing by abstracting out the echos into functions. Makes it easier to generate a syntactically correct xml file, too. Then you have the problem of getting a DTD from the program logic.

    Too much like hard work ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •