Sponsored Content
Full Discussion: formatting output in html
Top Forums Shell Programming and Scripting formatting output in html Post 302082684 by Corona688 on Thursday 3rd of August 2006 01:03:32 AM
Old 08-03-2006
Outputting HTML is easy. HTML is text.

Code:
#!/bin/sh

echo "<html><body>This is HTML</body></html>"

PHP is a language specifically designed to present results in HTML. It has the power of a full scripting language, and you can intermix raw HTML and PHP with ease.
Code:
<html>
  <body>
<?php   $dspec=array(   1       =>      array("pipe", "w")      );
        $proc = proc_open("ps ux", $dspec, $pipes );

        ($proc) || die("Couldn't run 'ps ux'");         ?>
    <table width='100%'>
      <tr>
<?php   $line=fgets($pipes[1]);
        $titles=preg_split("/[\s]+/",$line);

        for($n=0; $n<sizeof($titles); $n++)
        {                                               ?>
        <th><?=$titles[$n]?></th>
<?php   }                                               ?>
      </tr>
<?php   while($line=fgets($pipes[1]))
        {
                $titles=preg_split("/[\s]+/",$line);
                                                        ?>
      <tr>
<?php           for($n=0; $n<sizeof($titles); $n++)
                {                                               ?>
        <td><?=$titles[$n]?></td>
<?php           }                                               ?>
     </tr>
<?php   }       ?>
    </table>
  </body>
</html>
<?php   proc_close($proc);      ?>

This will produce an HTML table like so:

Code:
<html>
  <body>

    <table width='100%'>
      <tr>
        <th>USER</th>
        <th>PID</th>
        <th>%CPU</th>

        <th>%MEM</th>
        <th>VSZ</th>
        <th>RSS</th>
        <th>TTY</th>
        <th>STAT</th>
        <th>START</th>

        <th>TIME</th>
        <th>COMMAND</th>
        <th></th>
      </tr>

      <tr>
        <td>apache</td>
        <td>13019</td>

        <td>0.0</td>
        <td>3.6</td>
        <td>16120</td>
        <td>8096</td>
        <td>?</td>
        <td>S</td>

        <td>Jul30</td>
        <td>0:00</td>
        <td>/usr/sbin/apache2</td>
        <td>-D</td>
        <td>USERDIR</td>
        <td>-D</td>

        <td>DEFAULT_VHOST</td>
        <td>-D</td>
        <td>SSL</td>
        <td>-D</td>
        <td>PHP5</td>
        <td>-d</td>

        <td>/usr/lib/apache2</td>
        <td>-f</td>
        <td>/etc/apache2/httpd.conf</td>
        <td>-k</td>
        <td>start</td>
        <td></td>

      </tr>

      <snip for brevity>

    </table>
  </body>
</html>

...obviously not perfect, since PS doesn't use tabs for seperators(for reasons I can't imagine), but hopefully shows the idea.

PHP can be run on a web server -- the UNIX forums run on it -- in which case the code is executed and the results presented to you. You can also run it from the command prompt directly via 'php file.php'.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting the output

Hi all, Have the following code(1) producing the results(2 & 3). Would like to know if there is a way to format the two reports created in a similar fashion. IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt However when I attempt to do the same on... (7 Replies)
Discussion started by: Cameron
7 Replies

2. Shell Programming and Scripting

more help with formatting ls output...

Ok, for a fun project, my goal is to replicate the style of "catalog" on an old apple ] *A 002 SOMEAPPLESOFTFILE B 004 SOMEFILE T 006 SOMETEXT I 002 SOMEINTEGERFILE The first character is either " " or "*" depending on if the file is locked or not. Next is the filetype, so in... (1 Reply)
Discussion started by: patrick99e99
1 Replies

3. Shell Programming and Scripting

formatting output

Sorry for being a n00b, but I'm having a lot more trouble than I should with formatting the output to the program I finally completed. I'm basically looking for the linux equivalent to setw( ) from c++ so that I can print things in columns like this (but without the underlines lol): MISSPELLED: ... (4 Replies)
Discussion started by: aikaterinimak
4 Replies

4. Shell Programming and Scripting

html formatting using awk

Hi I have a file as given below: <table border=1> <TR><TH>Script Name</TH><TH>CVS Status</TH><TH>Script Location</TH></TR> <TR><TD><CENTER>Work Area: /home/ustst/</CENTER></TD></TR> <TR><TD><CENTER>admin_export.sh</CENTER></TD><TD><CENTER>Locally... (1 Reply)
Discussion started by: sudvishw
1 Replies

5. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

6. UNIX for Dummies Questions & Answers

How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes . The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to... (0 Replies)
Discussion started by: pinga123
0 Replies

7. UNIX for Dummies Questions & Answers

How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes . The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to... (7 Replies)
Discussion started by: pinga123
7 Replies

8. Shell Programming and Scripting

Formatting output

Hi, I have a file like this -------------------------- 1 aaa xxx 55 -------------------------- 1 aaa www 32 -------------------------- 2 bbb yyy 11 -------------------------- 2 bbb zzz 34 ------------------------- 2 bbb ttt ... (3 Replies)
Discussion started by: tdev457
3 Replies

9. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

10. Shell Programming and Scripting

HTML formatting in shellscript

I have written one script which connects to MYSQL database, fires one select query and send the results over an email, if there is any Output. But the Output which I am receiving over email is in text format. I need to get it dispalyed in tabular format to ensure better readability. Below is... (3 Replies)
Discussion started by: Sambit Sahu
3 Replies
All times are GMT -4. The time now is 08:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy