尝试从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());
client-> responseContent返回ssl错误。 但是脚本可以在终端上正常工作!非常感谢您的协助。
答案 0 :(得分:0)
该解决方案最终是将环境变量添加到Perl脚本中,而忽略了SSL验证:
$ ENV {PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;