2010-09-23 29 views
0

我有一个Perl脚本,可以在屏幕上输出多行输出。我需要捕获这些行,并将它们传送到一个电子邮件(/ bin/mail)或一个文本文件中,以便在另一个操作中通过/ bin邮件发送。实际上,我已经找到了简单(愚蠢)的方法,我使用bash包装来做邮件。看起来像,如何将Perl的多行输出发送到/ bin/mail?

#!/usr/bin/bash 
source /nethome/zog/.bash_profile 
cd /nethome/zog/bin/perl 
/nethome/zog/bin/perl/find_free_space.pl > text.file 
/bin/mail -s [email protected] [email protected] < text.file 

我想要使用Net :: SMTP做smtp位。至少可以说,上述不雅。

我看到了这样的事情:在计算器

open(MAIL, "| /bin/mail -s FreePorts me\@geemail.com") || 
    die "mail failed: $!\n"; print MAIL "This is how it goes." 

,但未能在标准输出重定向到邮件。我使用的是:

$complete_output .= "\n"; "|/bin/mail -s FreePorts zog\@geeemail.com" || die "mail failed: $!\n"; 

我不知道,如果你都需要看到的Perl脚本,以帮助,但it is on pastebin。请告诉我。

+0

你来得很近,请参阅http://stackoverflow.com/questions/655719/how-do-i-unalias-from-perls-stdout – msw 2010-09-23 03:34:33

回答

1

STDOUT不在这里玩。你忘了告诉我们什么吗?当您打印到MAIL文件句柄时发生了什么?这个输出是否成为消息?将多行发送到MAIL文件句柄时会发生什么?

你的代码是:

"|/bin/mail -s FreePorts zog\@geeemail.com" || die "mail failed: $!\n"; 

,什么也不做。这是一个字符串,这也是一个真正的价值。交替从来没有对模具分支。当你在问题中使用第一个代码时发生了什么?写一个小示例脚本,看看你是否可以发送邮件并进行测试,直到找出结果。例如,这是一个测试您的问题的完整脚本:

#!perl 
use strict; 
use warnings; 
open my $mail, '| /bin/mail -s FreePorts [email protected]'; 
print $mail "This is a test message from $$ at " . localtime() . "\n"; 
close $mail or die "The pipe failed!\n $?"; 

当您运行该操作时会发生什么?当您从命令行尝试相同的命令时会发生什么?

为什么不使用Perl模块(如Email :: *模块之一)而不是依靠外部命令?有很多关于进程间通信的知识,我认为你是在这方面的曲线。模块为您提供所有的细节,具有更好的界面,并且更加灵活。

+0

} #print“\ n”; $ complete_output。=“\ n”; “|/bin/mail -s FreePorts zog \ @ gmeeil.com”||死“邮件失败:$!\ n”; } – user455351 2010-09-23 18:31:12

+0

我有我认为是一个全局标量命名,“$ complete_output”在这个脚本收集所有的输出行。这工作。现在我需要能够将收集到的数据发送到/ bin/mail或/ usr/sbin/sendmail – user455351 2010-09-23 18:34:16

+0

用其他详细信息编辑您的问题。向我们展示一个完整的示例脚本,演示您遇到的问题。 – 2010-09-23 18:35:26

相关问题