Create an html page by using values generated by another script
Hi all I need to create a table and the values inside the table are to be fetched by running a shell script
The steps involved are as follows Example: > ./script1 OUTPUT: A 3 B 5 C 1 and so on > ./script1 Output: A 6 B 2 X 8 Basically im getting some values for each user (A,B,C etc) These are the results in various subjects i.e script1 gives me marks of students in Maths, script2 gives marks of students in Science etc. Note: script1, 2 are shell scripts returning output on screen. Now I need this data as a table or categorised form html page. i.e. A page having headings like MATHS SCIENCE SST in the rows I have users (A,B,C) and each column contains marks for the user taken from script1, script2 upto script n for n subjects So for doing this I run the master script -< which in turn runs script1,2...n and create the corresponding html by printing values categorically or in some table form, which can be read easily. I hope i am clear what the requirement is. Many thanks |
If you really want text -> html, try http://txt2html.sourceforge.net/.
Alternately, if you just need a text layout that looks like a tabular report, then re-direct your scripts' outputs to a file and write some code in eg bash, Perl, whatever to re-format it. Some good bash links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ Perl http://www.tizag.com/perlT/index.php http://perldoc.perl.org/ http://www.perlmonks.org/?node=Tutorials |
Your sample output does not contain any HTML markup. How does it differ from the input data? How do you want the table to look? Does the output need to create a complete HTML page, or just the markup related to the table itself? What does the input data look like?
It sounds like your data is embedded in the script. This is generally not a good practice; data and code should be separate entities. A script should run, reading the data from a specified data file. Code:
<H1>MATH</H1> --- rod. |
Attempted solution
I have written a bash script but had to make some assumptions. Also to make it less abstract I work with example data - real subjects, names and marks. This bash script assumes student list is the same for each script, so if ./maths outputs the scores for John, Frank and Betty in that order than so does english, science etc. and that the script is named as per the academic subject, so ./maths, ./science, ./english rather than literally script1, script2, script3.
To be clear I imagine ./maths outputs: Code:
John 30 Code:
John 100 Code:
maths english master.sh: Code:
#!/bin/bash |
Just an amendment, in case the scripts are literally called ./script1 ./script2 etc. Still the headings have to come from somewhere so at the moment subject names are still hard coded.
Code:
#!/bin/bash |
thanks leehankin for your code.
Well the scenario is by running ./math (lets change script name), I get a list of all students, but the students who didnt give the paper or scored 0 or any (not applicable) candidate is "NOT REPORTED" by the script. However I need only some students who are a part of my class so from 'n' students reported i used egrep on output to have names of students in my class only i.e. ./math may return Quote:
Quote:
Although I would have loved to have a table like (what u made) Quote:
Since this no value box makes the problem more complex. (:newbie:and can be taken 1nce i get the easier thing done) I'm ok having a master script which runs ./math.pl ./science.pl ./sst.pl
I hope im clear enough. @chrism01 The data im getting is from perl script whose working is a black box to me ( im new to it), so I'm trying to utilize that output. I'm assuming you are saying that rather than making a new script I must change the math.pl and science.pl to do the work directly ..right? |
If each subject can be an individual table, and it doesn't matter about 0 results, then the master script just really needs to add markup, as suggested by theNbomr.
The following will put the results side by side by nesting one HTML table inside another. (Assumes scripts are './maths.pl' './science.pl') Code:
#!/bin/bash |
Thanks lee, could you please tell where this is being echoed? I mean this should be written in an HTML file right? with a .html extension? and what does
Quote:
|
Quote:
Code:
./master.sh > output.html Quote:
Code:
IFS=$'\n' read LINE Code:
IFS=$'\n' read LINE Code:
do ... done Code:
<<< $(./$SUBJECT.pl) Code:
"<<< $(./$SUBJECT.pl)" I hope this makes sense. |
thanks lee, actually the commands were
Quote:
Quote:
Quote:
Therefore the readability is not very good, Can i have these in a better formatting something like 1. Having outlines for each table 2. More space between each table 3. A main heading "Test Results at the top of the page" And 1 more thing I forgot to mention, the page also has to show last year results as well ( done through another script eg. math_old.pl, science_old.pl,etc) which must come once all this year result tables are done. So should I add another simillar code again eg. Quote:
I can do more formatting in future, I just need a readable html by monday. So the page looks like: Quote:
|
Hi, the following is based on the example above. (At this stage I can see improvements that could be made (perhaps writing it in perl), commenting, using stylesheets etc.), but to keep things consistent it is basically the same format as before.
(In order to get the headings from the name of the script, assumes scripts are called './maths.pl' './science.pl' for this year, and './maths_old.pl' './science_old.pl' for last year.) Code:
#!/bin/bash |
In case it is more useful, here is how I would write it in Perl. Personally, I prefer this, because the headings can be named differently to the scripts, and also it puts each year into one big table rather than several side by side, and also handles if a student does not have a certain result for a subject.
master.pl: Code:
#!/usr/bin/perl |
All times are GMT -5. The time now is 05:41 AM. |