title: Curl fails upload with "NSS error -5938" when called from crontab
body: <p>I have a shell script that:</p>
  
  <ol>
  <li>downloads files from a database</li>
  <li>saves them as CSV files locally</li>
  <li>transfers the file to another server via FTP (using curl).</li>
  </ol>
  
  <p>When run manually, the script runs file, but when kicked off via crontab, it fails the third step. the output of CURL shows <code>NSS error -5938 (PR_END_OF_FILE_ERROR)</code> after the STOR command (which does not occur when running manually).</p>
  
  <p>Any thoughts? Some exerpts from my code/logs below:</p>
  
  <p>Crontab:</p>
  
  <pre class="lang-sh prettyprint-override"><code>    0 20 * * * cd /home/username/automation/process &amp;&amp; ./process.sh &gt; /home/username/automation/process/lastrun.log 2&gt;&amp;1
  </code></pre>
  
  <p>CURL command is run from another shell script ./totarget.sh:</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  curl -T $1 -ssl ftps://ftp.domain.com/ --user username:password --cacert /home/username/automation/process/output/team-ftp.pem -v
  </code></pre>
  
  <p>Output from CURL (paths/users/hosts replaced):</p>
  
  <pre><code>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: E=Team@domain.com,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: E=Team@domain.com,OU=Team Name,O=Company Name,L=City,ST=NY,C=US,CN=team.domain.com
  &lt; 220-Team Name FTP
  &lt; 220-Unauthorized use is prohibited
  &lt; 220 Access is logged
  &gt; USER username
  &lt; 331 Password required for username
  &gt; PASS password
  &lt; 230 Logged on
  &gt; PBSZ 0
  &lt; 200 PBSZ=0
  &gt; PROT P
  &lt; 200 Protection level set to P
  &gt; PWD
  &lt; 257 "/" is current directory.
  * Entry path is '/'
  &gt; EPSV
  * Connect data stream passively
  * ftp_perform ends with SECONDARY: 0
  &lt; 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)
  &gt; TYPE I
  &lt; 200 Type set to I
  &gt; STOR Filename.csv
  &lt; 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
  </code></pre>
  
  <p>I exported the site's self-signed cert and put it in team-ftp.pem, which is explicitly included in case the totarget.sh script. Could really use some insight as to why this runs for me, but not for the same user's crontab. </p>
  
  <p>Some system info:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ 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
  
  </code></pre>
  
  <p>Thanks in advance.</p>