从crontab调用时,Curl上传失败,并显示“ NSS错误-5938”

问题描述 投票:0回答:1

我有一个shell脚本:

  1. 从数据库下载文件
  2. 将它们另存为CSV文件
  3. 通过FTP(使用curl)将文件传输到另一台服务器。

手动运行时,脚本运行文件,但是通过crontab启动时,该脚本无法执行第三步。 CURL的输出在STOR命令后显示NSS error -5938 (PR_END_OF_FILE_ERROR)(手动运行时不会出现)。

有什么想法吗?以下是我的代码/日志的摘录:

Crontab:

    0 20 * * * cd /home/username/automation/process && ./process.sh > /home/username/automation/process/lastrun.log 2>&1

CURL命令是从另一个Shell脚本运行的。/totarget.sh:

#!/bin/bash
curl -T $1 -ssl ftps://ftp.domain.com/ --user username:password --cacert /home/username/automation/process/output/team-ftp.pem -v

CURL的输出(已替换路径/用户/主机):

Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /home/username/automation/process/output/team-ftp.pem
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
*       subject: [email protected],OU=Team Name,O=Company Name,L=City,ST=NY,C=US,CN=team.domain.com
*       start date: Aug 07 21:42:43 2019 GMT
*       expire date: Aug 06 21:42:43 2020 GMT
*       common name: team.domain.com
*       issuer: [email protected],OU=Team Name,O=Company Name,L=City,ST=NY,C=US,CN=team.domain.com
< 220-Team Name FTP
< 220-Unauthorized use is prohibited
< 220 Access is logged
> USER username
< 331 Password required for username
> PASS password
< 230 Logged on
> PBSZ 0
< 200 PBSZ=0
> PROT P
< 200 Protection level set to P
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||61786|)
*   Trying 123.456.789.123...
* Connecting to 123.456.789.123 (123.456.789.123) port 61786
* Connected to team.domain.com (123.456.789.123) port 990 (#0)
> TYPE I
< 200 Type set to I
> STOR Filename.csv
< 150 Opening data channel for file upload to server of "/Filename.csv"
* Doing the SSL/TLS handshake on the data stream
*   CAfile: /home/username/automation/process/output/team-ftp.pem
  CApath: none
* NSS error -5938 (PR_END_OF_FILE_ERROR)
* Encountered end of file
* Failure sending ABOR command: SSL connect error
* Closing connection 0

我导出了站点的自签名证书,并将其放在team-ftp.pem中,以防totarget.sh脚本显式包括在内。真的可以使用一些洞察力来了解为什么它适合我,但不适用于同一用户的crontab。

一些系统信息:

$ uname -a
Linux hostname.domain.com 3.10.0-693.11.1.el7.x86_64 #1 SMP Fri Oct 27 05:39:05 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

$ curl --version
curl 7.44.0 (x86_64-unknown-linux-gnu) libcurl/7.44.0 OpenSSL/1.0.2g
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP UnixSockets

提前感谢。

curl cron openssl ftps
1个回答
0
投票

我能够直接从crontab调用bash,然后将shell脚本传递给它,从而解决了该问题:

 0 20 * * * bash -c "cd /home/username/automation/process && ./process.sh > /home/username/automation/process/lastrun.log 2>&1"

希望这将对以后的人有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.