Arranging the command output into an html table format

Hi,
I need to format a command output for the beolow command:

runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database"

The output will be:

"ABC - cert name"
       From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT
   XYZ - cert name
       From: Tuesday, March 29, 2016 4:44:09 PM CDT To: Thursday, March 29, 2018 4:44:09 PM CDT

I need to format the above output into the below html table with the below columns,

       Server Name     Certificates Expiry < 90?     Certificate Name     Expiry Date (To: xxxx)

The example of the table is as below:

ServerName     CertsExpiry?     CertName     ExpiryDate 
server1     YES     cert1.com      Thu Sep 21 10:16:58 CDT 2017 
server2     YES     cert2.com      Thu Sep 21 09:56:57 CDT 2017 

Can you please advise how to format the above output of the command?.

Thanks,
bdpl

What have you tried? Please show us your code, and we can help you get it working.

Here is the code snippet what I am trying to play. I see the code is capturing for the first line of output but not for the 2nd line of the output.

typeset OLDIFS=$IFS
IFS='
'
set -A xy `runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | sed '1n;N;N;N;s/\n/-/g' | grep -v "Certificates in database"`
m=0
for j in ${xy[@]}
do
CERT_NAME=`echo ${xy[$m]} | cut -d "-" -f 1`
FROM_DATE=`echo ${xy[$m]} | awk -v FS="(From:|To:)" '{print $2}'`
TO_DATE=`echo ${xy[$m]} | awk -v FS="(To:|-)" '{print $2}'`

echo "<tr><td> $QM </td> <td style="background-color:red"> YES </td><td> $CERT_NAME </td> <td style="background-color:red">  $TO_DATE </td> </tr>" >> SSLExpiryCheck.html

let m=$m+1
done
typeset IFS=$OLDIFS
echo "</table></body> </html>" >> SSLExpiryCheck.html

The content of the file 'SSLExpiryCheck.html' is:

<html> <body> <h1> Certificates expiring in the next 90 days on server1: QM1.kdb</h1>
<table border=1> <tr> <th style=background-color:orange> Server Name </th> <th style=background-color:orange> Certificates Expiry < 90? </th><th style=background-color:orange> Certificate Name </th> <th style=background-color:orange> Expiry Date </th> </tr>
<tr><td> QM1 </td> <td style=background-color:red> YES </td><td>    "Entrust.net Secure Server Certification Authority" </td> <td style=background-color:red>         From: Tuesday, May 25, 1999 11:09:40 AM CDT  </td> </tr>
</table></body> </html>

Whereas the actual output of the command is:

runmqckm -cert -list -db QM1.kdb -pw xxxx -expiry 700 | sed '1n;N;N;N;s/\n/-/g' | grep -v "Certificates in database"
   "Entrust.net Secure Server Certification Authority"-       From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT-   ibmwebspheremqqm1-       From: Tuesday, March 29, 2016 4:44:09 PM CDT To: Thursday, March 29, 2018 4:44:09 PM CDT

I dont see the entries for the - ibmwebspheremqqm1 expiry details in SSLExpiryCheck.html output file.

Please advise whether I am missing anything. Thanks.

Give people a chance to understand your problem. None of the sample data given in post#1 or #3 do match each other, and the code you provided doesn't help either. For instance, your data from runmqckm has one line only, as does the HTML table. As your verbal description is far from being clear, and code and data don't allow conclusions on how to proceed, why don't you start over and provide

  • your system's info like OS, shell, tools and their versions.
  • a clear description of the problem.
  • basic data like the unmodified output of the runmqckm program.
  • the target (desired) output (matching the input data!).