我一直在使用这个模块编写简单的脚本来登录服务器并执行单个命令。
use Net::SSH qw(sshopen2);
use strict;
my $user = "username";
my $host = "hostname";
my $cmd = "command";
sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
while (<READER>) {
chomp();
print "$_\n";
}
close(READER);
close(WRITER);
但我需要$ cmd变量来执行此操作。
my $dir = "/srv/archive/$date";
my $time = `date`;
open my $LOG, '>>', '/srv/archive/test.log';
if ( ! -e $dir )
{
my $to = 'xxxxx@xxxxx.com';
my $from = 'node0@example.com';
my $subject = '**DROP FILE TEST ALERT**';
my $message = "Please check if the $date directory exists";
open(MAIL, "|/usr/sbin/sendmail -t");
# Email Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
# # Email Body
print MAIL $message;
close(MAIL);
print "Email Sent Successfully\n" ;
print $LOG "$time (Bad)";
}
else
{
print "The directory exists!\n";
print $LOG "$time (Good)\n";
}
我之所以使用它是因为我不允许在服务器内执行脚本。提前谢谢。
答案 0 :(得分:4)
手动将标题打印到select case 1 when 0 then "No payment made" when 1 then "Payment made accordingly" end from payments
不再是发送电子邮件的好方法。 Modern email contains multiple, complicated guards against spammers。大多数邮件服务器和客户端都会将您的邮件拒绝为垃圾邮件。
没有理由要在远程服务器上发送电子邮件。而是通过普通的SMTP连接发送邮件。请考虑使用Email::Sender代替。
如果您绝对必须从远程服务器发送邮件,请编写脚本(也使用Email :: Sender)并调用该脚本。