【问题标题】:Insert results of bash script into html table将 bash 脚本的结果插入到 html 表中
【发布时间】:2019-07-05 05:06:28
【问题描述】:

我有一个脚本可以输出应用程序的最后 3 个日志。我正在寻找将这些数据放入我能够发送给我的同事的 HTML 表中。

以下是我目前拥有的命令,但它没有打印出我要查找的内容。

awk -F':' 'BEGIN{print "<table border=1 cellpadding=1 cellspacing=0 bordercolor=BLACK>
<tr>
    <td>Environment</td>
    <td>Default Shell</td>
</tr>"}{ print "
<tr>
    <td>"$success"</td>
    <td>"$(NF)"</td>
</tr>"$(NF)"</td></tr>"}END { print "</table>" } ' /var/tmp/pid_test.sh

任何帮助将不胜感激!

【问题讨论】:

  • 现在,如果我们知道 /var/tmp/pid_test.sh 的样子(顺便说一句,.sh 是日志文件的奇怪扩展名?),以及您想要的输出是什么......
  • 打印的是什么,为什么不使用awk 标记您的帖子?根据文件名,我猜你需要脚本的输出而不是脚本的文本。
  • 我在我的/var/tmp/pid_test.sh 文件中提取日志。是的,我需要脚本的输出,而不是文本。

标签: html linux bash logging server


【解决方案1】:

试试

{your script that prints output} | awk ...

例如

$ echo -e "a:1\nb:2" | 
awk -F: 'BEGIN {print "<table>"}
               {print "<tr><td>" $NF "</td></tr>"}
         END   {print "</table>"}'

给予

<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
</table>

管道到

$ script ... | awk ... | mailx -s "test results" test@example.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多