ssl - 从 CRON 发出调用 REST(特别是端口 443)的问题

标签 ssl cron

我在尝试从 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/

相关文章:

php - cron 会执行 php 文件还是只执行 CGI 脚本?

Java SSL 重新协商(从 SSL 到清除 channel )

java - 如何为 Java 指定服务器首选的 SSL 密码套件顺序?

php - Symfony2 打开 stream_socket_client()

linux - 某些 Htaccess 命令阻止了我的 linux cron 作业

cron - 我如何设置一个 Vagrant box 以始终有一个 cron 工作?

ssl - 是否有用于测试证书名称不匹配的域?

xcode - 机器人创建失败,错误为 : An SSL error has occurred and a secure connection to the server cannot be made

docker - 从主机启动docker-compose中的cron作业?

python - 在 Raspberry Pi 重启时运行 Python3 模块