我有一个包含设备名称的文件,它是shell脚本根据区域的输出。所以区域是可变的,可以改变....例如devicelist =设备。地区
现在我想把这个设备列表添加到邮件正文中。对于发送电子邮件,我使用perl脚本,我已经尝试了下面的方法,但它不工作…
my $file = "$ENV{devicelist}";
open my $fh, '<', $file;
print while (<$fh>);
I am getting this message as : GLOB(0x11aeea8)
Perl脚本....
my $file = "/tmp/devicelist";open my $fh, '<', $file;print while (<$fh>);
$logger->debug("$logid >> Device names is $deviceinfo");
$smtp->datasend("Customer Name : $custnamenn");
$smtp->datasend("Site Location : $sitenamenn");
$smtp->datasend("Region : $regionnn");
my $file = "/tmp/devicelist";
open my $fh, '<', $file;
print while (<$fh>);
$smtp->datasend("Device Info : $deviceinfonn"); 1st way
$smtp->datasend("Device Info perl : $fhnn"); 2nd way
这个请求是处理我在哪里发送电子邮件时,有超过10个设备下来,我想要呈现这10个设备的名称。其他信息显示得很好,因为这些是存储在变量中的单个值,如区域,状态等。
谢谢
你所需要做的就是改变
print while (<$fh>);
$smtp->datasend($_) while (<$fh>);
您是否在问如何将文件的内容加载到变量中?
my $file; { local $/; $file = <$fh>; }
默认打印到标准输出,而不是$smtp->data send()
发送字符串参数的相同位置。
我想你只是想重写你的while循环并正确地引导输出;所以…
print while (<$fh>); #is basically saying:
while (<$fh>) {
print;
} #but in your smtp block, you don't want to be printing, so write
foreach $fileline (<$fh>) { $smtp->datasend($fileline); }
一旦你尝试了,如果它工作,因此这解释了什么是错误的,然后看看一次吸进整个文件,像这样:
my $file = "/tmp/devicelist";
open my $fh, '<', $file;
my $filecontents; { local $/; $filecontents = <$fh>; }
$smtp->datasend($filecontents);
除此之外,当你说:
print while (<$fh>);
I am getting this message as : GLOB(0x11aeea8)
你的意思是,你不想得到GLOB(0x11aeea8)或这是正确的输出?如果是前者,我想那是因为你想写这样的东西:
while (<$fh>) {print $_;}