If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > XML based output from Unix Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-23-03, 08:38
descueta119 descueta119 is offline
Registered User
 
Join Date: May 2003
Location: Australia
Posts: 2
Lightbulb 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?
Reply With Quote
  #2 (permalink)  
Old 06-08-03, 23:05
another2 another2 is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 06-10-03, 01:41
descueta119 descueta119 is offline
Registered User
 
Join Date: May 2003
Location: Australia
Posts: 2
Quote:
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.
Reply With Quote
  #4 (permalink)  
Old 07-22-03, 16:51
chillies chillies is offline
Registered User
 
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 ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On