【问题标题】:Mailing using Unix with error Files Attached使用带有错误文件的 Unix 发送邮件
【发布时间】:2012-09-26 10:22:12
【问题描述】:

我有两个文件 (.csv),分别是 File1.csvFile2.csv,带有 'INVALID' 记录,在 Informatica 作业结束时生成。

我正在使用以下命令搜索文件名'INVALID',然后如果其中一个文件有 'INVALID' 记录,我必须邮寄该特定文件,如果两者都有无效记录,则这两个文件都必须是邮寄给用户。

$ grep -il "invalid" File1.csv File2.csv | xargs -I'{}' uuencode {} | mailx -s"files" mymail@gmail.com

我收到的邮件附有两个文件,但没有记录。

我也尝试使用 -a 附加文件:

$ grep -il "invalid" File1.csv File2.csv | xargs -I'{}' mailx -s"files" -a {} mymail@gmail.com

但是上面的命令抛出错误:

mailx: illegal option -- a
Usage: mailx -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address
             -s SUBJECT -f FILE users

【问题讨论】:

    标签: unix grep xargs mailx


    【解决方案1】:

    我认为 grep 中的选项是您出错的地方。 “l”(小 L)选项用于打印文件名而不是文件内容,基于 grep man:

      -l, --files-with-matches
          Suppress normal output; instead print the  name  of  each  input
          file  from  which  output would normally have been printed.  The
          scanning will stop on the first match.
    

    因此,如果您只是从第一个命令中删除“-l”,我认为它会将您需要的文件内容通过电子邮件发送给您,因此命令如下:

    $ grep -il "invalid" File1.csv File2.csv | xargs -I'{}' uuencode {} | mailx -s"files" mymail@gmail.com
    

    【讨论】:

      猜你喜欢
      • 2013-04-15
      • 2014-10-08
      • 2015-03-25
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 2011-08-30
      相关资源
      最近更新 更多