html - 如何绘制包含 SQL 查询结果的 HTML 表并在 Shell 脚本中发送到邮件
问题描述
我想绘制包含 SQL 查询记录的 HTML 表并在 shell 脚本中发送到邮件。这是shell脚本: -
#!/usr/bin/ksh
out=$(for id in 1 2 3 4
do
sqlplus -s <user>/<password>@<db> <<EOF
spool out.txt;
select id, count(*) from <table> where id=${id};
spool off;
exit;
EOF
done)
echo ${out} > out.txt
(uuencode out.txt out.txt)| cat out.txt| mailx -s "Before" abc@xyz.com
而且我得到了不同格式的查询输出,而不是 HTML 表格格式。表格格式应该是这样的(在有边框线的表格中)
ID Results
Before After
1 12 15
2 27 30
3 45 52
你能帮我画出这条记录的HTML表格吗?
解决方案
现在,我在我的环境中重现了这个问题
#!/usr/bin/ksh
#start table
echo "<table><thead><tr><th>ID</th><th>BEFORE</th><th>AFTER</th></tr></thead><tbody><th>" > out.html
rot_sqlplus(){
sqlplus -s /nolog <<SQLPLUSEND
conn user/passwd@database
SET HEADING OFF;
SET FEEDBACK OFF;
SET ECHO OFF;
SET PAGESIZE 0;
select '<tr><td>'||ID|| '</td><td>' || BEFORE || '</td><td>' || BEFORE || '</td></tr>' from teste where id=$1;
quit
SQLPLUSEND
}
out=$(for id in 1 2 3 4
do
rot_sqlplus $id
done)
echo ${out} >> out.html
#finish table
echo "</th></tbody></table>" >> out.html
cat out.html
结果到 out.html
<table>
<thead>
<tr>
<th>ID</th>
<th>BEFORE</th>
<th>AFTER</th>
</tr>
</thead>
<tbody>
<th>
<tr>
<td>1</td><td>12</td><td>12</td>
</tr>
<tr>
<td>2</td><td>27</td><td>27</td></tr>
<tr>
<td>3</td><td>45</td><td>45</td>
</tr>
</th>
</tbody>
</table>
在浏览器中查看
推荐阅读
- amazon-web-services - 在 Rafay 上滚动日志
- amazon-web-services - 将消息发布到 SNS 而不是直接推送到 SQS 的优势
- firebase-storage - Firebase-storage 检索元数据带宽消耗
- autodesk-forge - 批量打开多个 Revit 模型 - 关闭 BIM360
- core-animation - 同步CALayer绘图
- apache-spark - 在 PySpark 中将数据帧写入 CSV 后重命名文件
- excel - 用户表单中的多行字符串问题
- tensorflow - 自定义层不支持序列化自定义激活函数
- ruby - 使用 RSpec 测试私有字段
- github - ci github-actions “env-cmd:未找到”