Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Technical Support _ inserting command output in specific html table

Posted by: aristosv Apr 6 2016, 04:31 AM

I use the following commands in a bash script, to output the CPU and disk usage on a computer.

I would like to import this output directly in an HTML file with tables.

How can I get the ouput of these commands to go in a specific table, as shown in the HTML code below?

CODE
echo $[100-$(vmstat|tail -1|awk '{print $15}')]'%'
df -h /dev/sda1 | awk 'NR>1{print $5}'


CODE
<html>
<head>
<title>Report</title>
</head>
<body>
<table>
    <tr>
        <td></td>
        <td>CPU Usage</td>
        <td>Disk Usage</td>
    </tr>
    <tr>
        <td>Computer1</td>
        <td></td>
        <td></td>
    </tr>
    </table>

</body>
</html>

Posted by: michaelk Apr 6 2016, 05:42 AM

You can create dynamic content using just about any language. Untested but you should get the general idea. You need to enable running scripts in your web server's configuration files. You can find out by googling.

CODE
#!/bin/bash

cpu=$( $[100-$(vmstat|tail -1|awk '{print $15}')] )
usage=$( df -h /dev/sda1 | awk 'NR>1{print $5}' )

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Report</title>'
echo '</head>'
echo '<body>'
echo '<table>'
   echo '<tr>'
         echo  ' <td></td>'
        echo '<td>CPU Usage</td>'
        echo '<td>Disk Usage</td>'
    echo '</tr>'
    echo '<tr>'
        echo '<td>Computer1</td>'
        echo "<td>$cpu</td>"
        echo  "<td>$usage</td>"
     echo '</tr>'
     echo '</table>'
echo '</body>'
echo '</html>'

exit 0

Posted by: aristosv Apr 7 2016, 06:30 AM

this helped. Thanks

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)