【问题标题】:Condense multiple files to a single BASH script将多个文件压缩为单个 BASH 脚本
【发布时间】:2013-09-13 21:03:05
【问题描述】:

我有一个 .body、.script 和 .sql,我想将它们压缩成一个脚本,但我不知道该怎么做。

.body 包含电子邮件消息。

.sql 将数据假脱机到 .csv:

.script 运行 .sql,并发送带有附件Report.zip 的电子邮件:

sqlplus $user/$pass@$db @script.sql

(cat script.body; uuencode Report.zip Report.zip) | mail -s "Report" user@domain.com -- -f no-reply@domain.com

有没有可能这(包括 SQL)都可以在一个 BASH 脚本中完成?

【问题讨论】:

  • ... sends an e-mail with the attached Report.csv。您的脚本似乎改用了Report.zip,并不是说它有什么不同,但您在发布问题时应该小心。
  • “浓缩”是什么意思。您想要的输出/操作是什么?
  • @cmh 目标是将所有内容都包含在一个脚本中,即 SQL 查询\假脱机和电子邮件。我只是不明白该怎么做,也许可以举个例子。
  • @devnull 我更新了问题,谢谢。
  • 让那些不同。这样可能更干净。

标签: bash


【解决方案1】:

如果您可以将脚本传递到 sqlplus 的标准输入中,您可以这样做:

sqlplus $user/$pass@$db << END
<contents of sql script here>
END

(cat script.body; uuencode Report.zip Report.zip) | mail -s "Report" user@domain.com -- -f no-reply@domain.com

如果你仍然想要标准输入(如果它可能要求输入密码或其他东西时很有用)并假设 sqlplus 不会尝试任何你可以做的脚本文件:

sqlplus $user/$pass@$db START <(cat << END
<contents of sql script here>
END)

(cat script.body; uuencode Report.zip Report.zip) | mail -s "Report" user@domain.com -- -f no-reply@domain.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多