0

我正在尝试从日志文件中打印一些值,但是 echo 打印在一行中,我只想在新行上打印每个结果。

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Acessos do usuario"
echo "</title></head><body>"
echo "$(egrep 'kelsen.faria' /var/squid/logs/access_custom.log | awk '{ print "Data: " $1, "Usuario: " $9, "IP: " $4 }' | uniq)"
echo "</body></html>

谢谢!

4

2 回答 2

0

使用egrep不带的命令echo

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Acessos do usuario"
echo "</title></head><body>"
egrep 'kelsen.faria' /var/squid/logs/access_custom.log | \
    awk '{ print "Data: " $1, "Usuario: " $9, "IP: " $4 }' | uniq
echo "</body></html>"

但显然您将输出用作 HTML。换行不会对你有太大帮助。您必须使用一些 html 格式。最简单的方法是插入<br>标签:

egrep 'kelsen.faria' /var/squid/logs/access_custom.log | \
    awk '{ print "Data: " $1, "Usuario: " $9, "IP: " $4, "<br>" }' | uniq
于 2013-07-26T11:06:02.217 回答
0

我设法通过使用表格使其正确显示,我想我会继续这种方式。

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Acessos do usuario"
echo "</title></head><body>"
echo "<table border="1">"
echo "<tr>"
echo "<th>Data</th>"
echo "<th>Usuario</th>"
echo "<th>IP</th>"
echo "</tr>"
echo "<tr>"
egrep 'kelsen.faria' /var/squid/logs/access_custom.log | \
    awk '{ print "<td>" $1, "</td>" "<td>" $9, "</td>" "<td>" $4 "</td>" "</tr>"
 }' | uniq
echo "</table>"
echo "</body></html>"
于 2013-07-26T14:30:59.160 回答