[英]Unable to run perl script for ssh login to Windows server (using Net::SSH::Perl) from crontab
I have a Perl script which is doing remote login to the Windows server via the Net::SSH::Perl
module. 我有一个Perl脚本,它正在通过
Net::SSH::Perl
模块远程登录Windows服务器。
If I run the script manually from my shell, it gives no error. 如果我从外壳程序手动运行脚本,则不会出错。 Running from a crontab, however, it connects properly to the remote Windows server but can't log in.
但是,它从crontab运行,可以正确连接到远程Windows服务器,但无法登录。
Here is the script: 这是脚本:
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";
On server A, By running this script in csh shell I get output like : 在服务器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 *
In the shell, perl test.pl
and sudo perl test.pl
both work fine. 在shell中,
perl test.pl
和sudo perl test.pl
都可以正常工作。
But running this script in cron as user root: 但是以root用户身份在cron中运行此脚本:
Test script is started on server name
Connecting : * with user * and pwd *
Connected ...
Now ,Trying to loggin ,sever ip : *
Note: I am able to do this on another Linux server B with same file permissions, same username, and same password. 注意:我能够在具有相同文件权限,相同用户名和相同密码的另一台Linux服务器B上执行此操作。 The difference is that when I run this Perl script without
sudo
on server B, I am getting this error: 区别在于,当我在服务器B上不使用
sudo
运行此Perl脚本时,出现此错误:
host key has changed! at /usr/local/share/perl5/Net/SSH/Perl/Kex/DH1.pm line 49
I don't see this error from Linux server A (the one on which I can't connect via cron) 我没有从Linux服务器A(无法通过cron连接的服务器)看到此错误
What is wrong and how can I solve it? 有什么问题,我该如何解决?
It looks like host key verification is failing preventing the authentication. 主机密钥验证似乎无法阻止身份验证。 There may be host keys stored in ~/.ssh/known_hosts in the user's(root) home directory try deleting the remote host key from "known_hosts" and then re-try.
用户(根)主目录中的〜/ .ssh / known_hosts中可能存储有主机密钥,请尝试从“ known_hosts”中删除远程主机密钥,然后重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.