对于bash / html中的CGI,我尝试在html数组中显示许多CSV文件中的一些信息。所以我用这个脚本:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLF MONITORING </title>
<h1> FRAME monitoring <font size=3> <a href="Index.sh">[ Index ]</a> </font> </h1>
<hr size="4" color="blue">
<style>
body{
background-color: #eff1f0;
}
</style>
</head>
<body>'
read a
test=$( echo $a | cut -d'=' -f2)
echo '<PRE>'
echo "FRAME : $test "
echo "------------------"
echo ""
echo "<table>"
echo "<tr>"
echo "<td>"
echo "<PRE>"
for fn in /var/www/cgi-bin/LPAR_MAP/*; do
awk -F',|;' 'NR==1 { split(FILENAME ,a,"[-.]");
print "DATE ========================== : " a[4] }
/'$test'/ {
print ""
print "LPARS :" $2
print "RAM : " $5
print "CPU 1 : " $6
print "CPU 2 : " $7
print ""
print ""}' $fn;
done
echo "</PRE>"
echo "</td>"
echo "</tr>"
echo "</table>"
echo '</PRE>'
echo '</body>
</html>'
输出为:
FRAME : MIAIBYC00
------------------
DATE ========================== : 20180705
LPARS :HSCL9010 This operation is only allowed when the managed system is in the Standby or Operating state.
RAM :
CPU 1 :
CPU 2 :
DATE ========================== : 20180122
LPARS :miaibv228
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
LPARS :miaibv158
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
LPARS :miaibv157
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
LPARS :OSvalidation
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
LPARS :miaibv104
RAM : 64
CPU 1 : 3.0
CPU 2 : 7
...
DATE ========================== : 20180124
LPARS :miaibv228
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
LPARS :miaibv158
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
LPARS :miaibv157
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
LPARS :OSvalidation
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
这个想法是:为一个“ Date ==========”创建一列,下面是他的信息,但是列数。
例如:
Date ========= XXXXX Date ============ XXXXX Date ============== XXXXXXX
LPARS :miaibv228 LPARS : XXXXXX LPARS : XXXXX
RAM : 8 RAM : XXXXXX RAM : XXXXXX
CPU 1 : 2.0 CPU 1 : XXXXX CPU 1 : XXXXX
CPU 2 : 4 CPU 2 : XXXXX CPU 2 : XXXXXX
在这个例子中,我只有3个“日期”和一些信息。但实际上,我有很多信息。
您有任何想法吗?
答案 0 :(得分:2)
我认为您只需要在循环内移动<td>
和<pre>
标签:
. . .
for fn in /var/www/cgi-bin/LPAR_MAP/*; do
echo "<td>"
echo "<PRE>"
awk -F',|;' 'NR==1 { split(FILENAME ,a,"[-.]");
print "DATE ========================== : " a[4] }
/'$test'/ {
print ""
print "LPARS :" $2
print "RAM : " $5
print "CPU 1 : " $6
print "CPU 2 : " $7
print ""
print ""}' $fn;
echo "</PRE>"
echo "</td>"
done
. . .