curl bash script works fine in shell but not work in cronjob The 2019 Stack Overflow Developer...

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What aspect of planet Earth must be changed to prevent the industrial revolution?

How do spell lists change if the party levels up without taking a long rest?

How do I design a circuit to convert a 100 mV and 50 Hz sine wave to a square wave?

Student Loan from years ago pops up and is taking my salary

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time?

Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)

Word for: a synonym with a positive connotation?

Is this wall load bearing? Blueprints and photos attached

How to make Illustrator type tool selection automatically adapt with text length

Windows 10: How to Lock (not sleep) laptop on lid close?

"is" operation returns false even though two objects have same id

Do I have Disadvantage attacking with an off-hand weapon?

Can withdrawing asylum be illegal?

Did the new image of black hole confirm the general theory of relativity?

Didn't get enough time to take a Coding Test - what to do now?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

What other Star Trek series did the main TNG cast show up in?

Identify 80s or 90s comics with ripped creatures (not dwarves)

Define a list range inside a list

Why can't devices on different VLANs, but on the same subnet, communicate?

Is there a writing software that you can sort scenes like slides in PowerPoint?

Huge performance difference of the command find with and without using %M option to show permissions



curl bash script works fine in shell but not work in cronjob



The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Come Celebrate our 10 Year Anniversary!Bash script works from prompt but not from cronbash shell command runs fine at command prompt, but not in my .sh script?Why doesn't this command work as a cronjob, while it works perfectly when typed in a shell?expect script works fine standalone not from bash scriptExecuting script remotely with “curl | bash” feedbackUbuntu 10.04 cronjob with curl dosen't workCURL & SSL failing on a specific sitebash scripts work fine when I run it from command line but not from cronshell script not working in cronjobCentOS 7: curl and wget not working





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a script using curl to do the job and set into crontabs.
Things were fine on redhat 7.5+ or CentOS 7.



But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.



OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT


Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
After trial tests overnight, I found a potential solution.



OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp

while :
do
[ -f /tmp/curl.tmp ] && break
sleep 1
done**

cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT


I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.



It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?



Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64

curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib








share







New contributor




Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    I have a script using curl to do the job and set into crontabs.
    Things were fine on redhat 7.5+ or CentOS 7.



    But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.



    OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
    [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
    curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
    cat /tmp/curl.tmp >> $OUTPUT
    echo >> $OUTPUT


    Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
    After trial tests overnight, I found a potential solution.



    OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
    [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
    curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp

    while :
    do
    [ -f /tmp/curl.tmp ] && break
    sleep 1
    done**

    cat /tmp/curl.tmp >> $OUTPUT
    echo >> $OUTPUT


    I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.



    It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?



    Red Hat Enterprise Linux Server 7.2 (Maipo)
    CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
    Kernel: Linux 3.10.0-327.el7.x86_64
    Architecture: x86-64

    curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
    zlib/1.2.7 libidn/1.28 libssh2/1.4.3
    Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
    pop3s rtsp scp sftp smtp smtps telnet tftp
    Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib








    share







    New contributor




    Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I have a script using curl to do the job and set into crontabs.
      Things were fine on redhat 7.5+ or CentOS 7.



      But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.



      OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
      [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
      curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
      cat /tmp/curl.tmp >> $OUTPUT
      echo >> $OUTPUT


      Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
      After trial tests overnight, I found a potential solution.



      OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
      [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
      curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp

      while :
      do
      [ -f /tmp/curl.tmp ] && break
      sleep 1
      done**

      cat /tmp/curl.tmp >> $OUTPUT
      echo >> $OUTPUT


      I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.



      It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?



      Red Hat Enterprise Linux Server 7.2 (Maipo)
      CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
      Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64

      curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
      zlib/1.2.7 libidn/1.28 libssh2/1.4.3
      Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
      pop3s rtsp scp sftp smtp smtps telnet tftp
      Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib








      share







      New contributor




      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have a script using curl to do the job and set into crontabs.
      Things were fine on redhat 7.5+ or CentOS 7.



      But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.



      OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
      [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
      curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
      cat /tmp/curl.tmp >> $OUTPUT
      echo >> $OUTPUT


      Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
      After trial tests overnight, I found a potential solution.



      OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
      [[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
      curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp

      while :
      do
      [ -f /tmp/curl.tmp ] && break
      sleep 1
      done**

      cat /tmp/curl.tmp >> $OUTPUT
      echo >> $OUTPUT


      I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.



      It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?



      Red Hat Enterprise Linux Server 7.2 (Maipo)
      CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
      Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64

      curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
      zlib/1.2.7 libidn/1.28 libssh2/1.4.3
      Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
      pop3s rtsp scp sftp smtp smtps telnet tftp
      Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib






      bash cron curl





      share







      New contributor




      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 7 mins ago









      Yeats RawYeats Raw

      1




      1




      New contributor




      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Yeats Raw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "2"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962873%2fcurl-bash-script-works-fine-in-shell-but-not-work-in-cronjob%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.













          Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.












          Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Server Fault!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962873%2fcurl-bash-script-works-fine-in-shell-but-not-work-in-cronjob%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          117736 Шеррод Примітки | Див. також | Посилання | Навігаційне...

          As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

          Маріан Котлеба Зміст Життєпис | Політичні погляди |...