无法从 crontab 运行 用于 ssh 登录到 Windows 服务器(使用 Net::SSH::Perl)的 perl 脚本

Unable to run perl script for ssh login to Windows server (using Net::SSH::Perl) from crontab

我有一个 Perl 脚本,它通过 Net::SSH::Perl 模块远程登录到 Windows 服务器。

如果我从 shell 手动 运行 脚本,它不会给出错误。 运行 来自 crontab,然而,它正确连接到远程 Windows 服务器但无法登录。

这是脚本:

use Net::SSH::Perl;
use Date::Calc qw(:all);
use DateTime::Format::Epoch;

$lin_host = `hostname -s`;
chomp($lin_host);
print "Test script is started on server $lin_host at time ",join(":",Now()),"\n";
$host = "any valid ip";
$user = "valid username";
$pass = "valid password";
$port = "valid port";

if ($ARGV[0] eq "eodupdate")
{
        $host = "valid host";
}

print "Connecting : $host with user $user and pwd $pass\n";
my $ssh = Net::SSH::Perl->new($host,port=>$port);
if ($ssh eq undef)
{
        print "Can't connect to server $host\n";
        exit;
}
print "Connected ... \nNow ,Trying to loggin ,sever ip : $host\n";
$ssh->login($user, $pass);
print "Yeah , successfully logged in to $host\n";

在服务器 A 上,通过 运行在 csh shell 中使用此脚本,我得到如下输出:

Test script is started on server name
Connecting : * with user * and pwd *
Connected ...
Now ,Trying to loggin ,sever ip : *
Yeah , successfully logged in to *

在 shell、perl test.plsudo perl test.pl 中都工作正常。

但是运行以 root 用户身份在 cron 中运行此脚本:

Test script is started on server name
Connecting : * with user * and pwd *
Connected ...
Now ,Trying to loggin ,sever ip : * 

注意:我可以在另一个 Linux 服务器 B 上使用相同的文件权限、相同的用户名和相同的密码执行此操作。不同之处在于,当我在服务器 B 上 运行 这个没有 sudo 的 Perl 脚本时,我得到这个错误:

host key has changed! at /usr/local/share/perl5/Net/SSH/Perl/Kex/DH1.pm line 49

我没有在 Linux 服务器 A(我无法通过 cron 连接的服务器)

中看到此错误

出了什么问题,我该如何解决?

主机密钥验证似乎失败,无法进行身份验证。用户(root)主目录中的 ~/.ssh/known_hosts 中可能存储了主机密钥尝试从 "known_hosts" 中删除远程主机密钥,然后重试。