1848733 Members
3754 Online
104036 Solutions
New Discussion

Re: Script Help Needed

 
SOLVED
Go to solution
Hunki
Super Advisor

Script Help Needed


Requirement :

We are using JBOSS as our java appl server, and need to have multiple instances of jboss servers runing on the box and for that to happen we need to extend the attached default file to have different port configurations currently the default file has a total of 3 configs - ports-default, ports-01, ports-02 and we need to extend that till ports ports-15.
I would like you all to help me in having a script which creates these additional port configurations.( eg. ports for ports-03 can be incremented by +1 in relation to ports-02 )
16 REPLIES 16
Hein van den Heuvel
Honored Contributor

Re: Script Help Needed

Hunki,

There are an awful lot of ports mentioned in there. Dozens per server definition.

It seems to me some need to be incremented by 100, not 1, like those 'rmiports' under
name="jboss:service=Naming"

You tell as EXACTLY which ports, to increment by how much and we might try for real.

Seems to me also you do not want to muck with this file directly. This stuff is clearly generated by a tool Use the tool to configure the extra servers?

Finally, to visuale this XML you can of course open it with the exploder under windoze, but you may want to try the "XML Notepad".
Google for: +"XML notepad" +site:microsoft.com

Good luck,
Hein.
Hunki
Super Advisor

Re: Script Help Needed

Q)You tell as EXACTLY which ports, to increment by how much and we might try for real.

A)Here is a sample ( attached ) of what I want ...ports-02 config is given along with comparable values from ports-01 and I want the same difference in each of my instances ( ports-03 onwards ... till ports-15 )

thanks for taking the challenge .

hunki

Sandman!
Honored Contributor

Re: Script Help Needed

where's the attachment?
Hunki
Super Advisor

Re: Script Help Needed

Oops .. here it is.
Ralph Grothe
Honored Contributor

Re: Script Help Needed

If you want to automate a bulk setting of ports, and since as it looks the whole JBoss config is stored in XML, I would suggest you use an XML parser for this task.
Honestly, I would expect that the JBoss maintainers already have such tools up their sleeve (they really cannot expect an admin clicking through piles of pages in a browser).
I for one, would help myself by parsing this stuff with one of the many Perl XML parsers (e.g. XML::Simple, relies on libexpat I suppose).

Madness, thy name is system administration
Sandman!
Honored Contributor

Re: Script Help Needed

Besides the XML parsing the script gets complicated owing to the presence of filenames that have numbers embedded in their names. For ex. the presence of number 4 in the "jboss-ws4ee.sar" filename. I don't suppose anything needs to be done with it? Meaning it does not need to be incremented?

From the sample input provided it seems like some ports need unit increments while others need 100 increments? And what about strings like "ports-02"? Do these need to be incremented for the next port config which I presume will be 3?

I guess those are some of the issues that needs to be addressed before a viable method of solving this can be concocted.
Hunki
Super Advisor

Re: Script Help Needed

Thanks for replying Sandman !!

Here are the answers to your queries :

Besides the XML parsing the script gets complicated owing to the presence of filenames that have numbers embedded in their names. For ex. the presence of number 4 in the "jboss-ws4ee.sar" filename. I don't suppose anything needs to be done with it? Meaning it does not need to be incremented?

Nope

From the sample input provided it seems like some ports need unit increments while others need 100 increments? And what about strings like "ports-02"? Do these need to be incremented for the next port config which I presume will be 3?

Yes

Hunki
Super Advisor

Re: Script Help Needed

So can anybody help please .
A. Clay Stephenson
Acclaimed Contributor

Re: Script Help Needed

Many can help but few are willing to. You want too much sugar for a dime. If this were me, I would manually edit a template file and put tags into it (e.g. "|~A1 ~|", "|~A2 ~|") and then write a parser that would substitute values for A1, A2, ...
It would be rather easy to add arbitrary values to the "base" substition based upon a command-line option. This sounds much like a Perl script to me.
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: Script Help Needed

Here's what I have been able to put together albeit in C. Let me know if this will work? Save the file compiling it with an ANSI C compiler and use the shell's I/O re-direction mechanism to supply the input file for example:

# cc parsexml.c -o parsexml
# cat infile | parsexml
or
# parsexml
========================== parsexml.c ==========================
#include
#include

int main(void)
{
int c, buf;

while ((c = getchar()) != EOF) {
if (isdigit(c))
buf = c - '0' + 10 * buf;
else {
if (buf)
printf(buf>100?"%d":"0%d",buf>100?buf+100:buf+1);
putchar(c);
buf = 0;
}
}
}
Hunki
Super Advisor

Re: Script Help Needed

Thanks for replying Sandman , but no luck , there is no change in the xml file after doing it.
Sandman!
Honored Contributor

Re: Script Help Needed

The XML file won't change in place. Instead save the stdout stream to an output file. The new file will have port numbers that are either 100 or 1 more than their counterparts in the input file viz.,

# cat infile | parsexml >outfile
or
# parsexml outfile

~cheers
Hunki
Super Advisor

Re: Script Help Needed

thanks Sandman , Cud please explain in detail of what the c code is doing. That would be very helpful. Thanks for a very sincere effort.

thanks,
hunki
Sandman!
Honored Contributor
Solution

Re: Script Help Needed

Another thing is that generating the port config file is a stepwise procedure and the output file becomes the input file for the next iteration. For example the input file you provided is the config file for port 02. To generate a config file for port 03 do as follows:

# parsexml port-03-file

The above command creates the config file for port 03. This file will become the input file for generating the config file for port 4...so on and so forth until all port configurations you need are exhausted i.e.

# parsexml port-04-file
.
.
.
# parsexml port-15-file

~hope it helps
Sandman!
Honored Contributor

Re: Script Help Needed

>Cud please explain in detail of what the c code is doing.

The program reads standard input (stdin), which can be redirected using the mechanisms provided by the shell, a character at a time scanning for digits. If the character read is not a digit then it is sent to standard output. On the other hand if the character is a digit then a local variable named "buf" collects them until a non-digit is encountered. At this point the integer variable "buf" is printed to standard output along with the non-digit character just read.

There are atleast a couple of ambiguities that are hard to resolve; one is the presence of digits within a filename which certainly is not up for incrementing and another is which numeric string needs to be incremented by 1 and which by 100. Hope it makes sense and hope it helps.

~cheers
Hunki
Super Advisor

Re: Script Help Needed

Thank You Very Much Sandman !