Jump to content

How to insert variable data in html table with unix commands


Aks

Recommended Posts

Hi I am using below script to create 3 tables adjacent to each other :

PARAMETERS

MOUNT

SIZE

1

f

fg

fgh

BEFORE_USAGE

USED

AVAILABLE

USE%

1

f

5

fg

fgh

t2

AFTER_USAGE

USED

AVAILABLE

USE%

Fvfev

kjhkj

kjgfhkg

fbghvg

gcfv

hfjghj

QUERY : I want to use df -h command which should fill the data  ( <td> ) in the above 3 table columns ( Parameters/ Before_Usgae/After_Usage). 

BEFORE USAGE : The disk space before clearing the space on the server.

AFTER USAGE : Disk space after clearing the space.

The problem here is : I am able to write the code in linux to generate the table like above ( next to each other) but unable to generate the data for ( Mount/size) , ( Used/available/use%) in runtime. 

Please help me how can i achieve this.

-------------------------
#! /bin/bash

MailTO=xyz@gmail.com
DATE=`/bin/date '+%Y%m%d-%H%M%S'`
HOST=`hostname`
ALERT_DIR_COUNT=`df -Ph | grep -v "Use%" | sed 's/%//g' | awk '$5 > 70 {print $1,$2,$3,$4,$5"%",$6;}' | column -t | wc -l`


(
printf "To: xyz@gmail.com\n"
printf "Subject:$HOST\n :$ALERT_DIR_COUNT\n mounts reached threshold & Logs Cleared : $Numberofdays days\n"
printf "Content-Type: text/html\n"
printf "<html>\n"
printf "<body>\n"

df -Ph | awk '

BEGIN {

printf "<table border="1" cellspacing="0" cellpadding="0">"
printf "<tr>"
printf "<td width="40">"
printf "<table width="100" border="1" cellspacing="0" cellpadding="1">"
printf "<tr>"
printf "<th style=\"font-size:12px\" bgcolor=#B2BABB align=center colspan="2">PARAMETERS</th>"
printf "<tr>"
printf "<th style=\"font-size:12px\" bgcolor=#EAEDED>MOUNT</th>"
printf "<th style=\"font-size:12px\" bgcolor=#EAEDED>SIZE</th>"
printf "</tr>"
printf "<tr>"
printf "<td>1</td>"
printf "<td>f</td>"
printf "</tr>"
printf "<tr>"
printf "<td>fg</td>"
printf "<td>fgh</td>"
printf "</tr>"
printf "</table>"
printf "</td>"
printf "<td width="30">"


printf "<table width="100" border="1" cellspacing="0" cellpadding="1">"
printf "<tr>"
printf "<th style=\"font-size:12px\"bgcolor=#73C6B6 align=center colspan="3">BEFORE_USAGE</th>"
printf "<tr>"
printf "<th style=\"font-size:12px\" bgcolor=#D0ECE7>USED</th>"
printf "<th style=\"font-size:12px\" bgcolor=#D0ECE7>AVAILABLE</th>"
printf "<th style=\"font-size:12px\" bgcolor=#D0ECE7>USE%</th>"
printf "</tr>"
printf "<tr>"
printf "<td>1</td>"
printf "<td>f</td>"
printf "<td>5</td>"
printf "</tr>"
printf "<tr>"
printf "<td>fg</td>"
printf "<td>fgh</td>"
printf "<td>t2</td>"
printf "</tr>"
printf "</table>"
printf "</td>"
printf "<td width="30">"

printf "<table width="100" border="1" cellspacing="0" cellpadding="1">"
printf "<tr>"
printf "<th style=\"font-size:12px\" bgcolor=#7FB3D5 align=center colspan="3">AFTER_USAGE</th>"
printf "<tr>"
printf "<th style=\"font-size:12px\" bgcolor=#D6EAF8>USED</th>"
printf "<th style=\"font-size:12px\" bgcolor=#D6EAF8>AVAILABLE</th>"
printf "<th style=\"font-size:12px\" bgcolor=#D6EAF8>USE%</th>"
printf "</tr>"
printf "<tr>"
printf "<td>Fvfev</td>"
printf "<td>kjhkj</td>"
printf "<td>kjgfhkg</td>"
printf "</tr>"
printf "<tr>"
printf "<td>fbghvg</td>"
printf "<td>gcfv</td>"
printf "<td>hfjghj</td>"
printf "</tr>"
printf "</table>"
printf "</td>"
printf "</tr>"
printf "</table>"
}
  END { print "</table>" }'
printf "</body>\n</html>\n" ) | /usr/sbin/sendmail $MailTO
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...