我正在尝试从日志文件中打印一些值,但是回显打印在一行中,我只想在新行上打印每个结果。
#!/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>
谢谢!
答案 0 :(得分: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
答案 1 :(得分: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>"