我在尝试从 cron 脚本执行 REST 调用时遇到了最大的麻烦。
我的脚本在终端中作为 root 用户运行良好,但是当我从 root CRON 设置它时,出现以下错误:
$VAR1 = 'Can\'t connect to 172.16.250.159:443 (certificate verify failed)
LWP::Protocol::https::Socket: SSL connect attempt failed with unknown error error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at /opt/algosec/perl5/lib/perl5/LWP/Protocol/http.pm line 51.
';
我的 cron 看起来像这样:
*/5 * * * * /usr/share/fireflow/local/etc/site/lib/pending_ritm_kickoff_script.pl
我的 perl 脚本运行以下内容:
my $client = REST::Client->new({
hostname => ''
});
my $response = '';
$client->addHeader('Content-Type', 'application/json');
my %rec_hash = (
'username' => $username,
'password' => $password,
);
my $json_body = encode_json(\%rec_hash);
$client->POST("$endpoint/APP1/api/authentication/authenticate", "$json_body");
open(my $fh, '>', '/tmp/cron_report_1.txt');
print $fh Dumper($client->responseContent());
close $fh;
$response = decode_json($client->responseContent());
客户端->responseContent 返回 ssl 错误。 但是脚本在终端上运行良好!非常感谢任何帮助。
最佳答案
解决方案最终是向 Perl 脚本添加一个环境变量,忽略 SSL 验证:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
关于ssl - 从 CRON 发出调用 REST(特别是端口 443)的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54041058/