Curl don't work on cron execution

7,979

Solution 1

I have solved the problem, were i was able to run script manually but when i tried from cron it failed with "curl: not found".

wherever you`ve written "curl" in your script put complete path.

How to find complete path.? Just run command on your machine "which curl" you`ll see path for curl and copy paste in your script.

Solution 2

When you run a script from the command line, your own environment variables, including $PATH, are in use. When you run a script from cron, however, the $PATH is different. My guess is that you don't have curl in a path that cron has in its $PATH environment variable.

Solution: In your script, use the full path to cron.

Share:
7,979

Related videos on Youtube

Filipiz
Author by

Filipiz

Updated on September 18, 2022

Comments

  • Filipiz
    Filipiz almost 2 years

    I have bash a script like the following

    #!/bin/bash
    
    date
    
    curl http://lab.nextt.com.br/somefile1.html -z ../public_html/somefile1.html -o ../public_html/somefile1.html --silent --show-error --location
    
    curl http://lab.nextt.com.br/somefile2.html -z ../public_html/somefile2.html -o ../public_html/somefile2.html --silent --show-error --location
    
    curl http://lab.nextt.com.br/somefile3.html -z ../public_html/somefile3.html -o ../public_html/somefile3.html --silent --show-error --location
    
    curl http://lab.nextt.com.br/somefile4.html -z ../public_html/somefile4.html -o ../public_html/somefile4.html --silent --show-error --location
    

    and I have a cronttab like this

    * * * * * /home/user/cronjobs/cronjob-updatefiles >> /home/user/cronjobs/log
    

    My intention is: whenever there is an update on a public file, download it to my server.

    So good so far.

    When I run the script manually on the shel, the files are downloaded and updated as expected.

    And the cron is running the... The /home/user/cronjobs/log is being updated with the date (on the beggining of the script). But the curl commands are not executed via cron. The files are not updated.

    Why when I run directly on the shell it works and when I run via cron it does not?

    • Dennis Kaarsemaker
      Dennis Kaarsemaker over 11 years
      Your question is off topic for Serverfault because it doesn't appear to relate to servers/networking or desktop infrastructure in a professional environment. It may be on topic for Superuser but please search their site for similar questions that may already have the answer you're looking for.
  • Filipiz
    Filipiz over 11 years
    Yeah.. not only the full path to cron but also the full path of the files I was referencing... I posted the solution I found right now.. thank for helping!
  • Jenny D
    Jenny D over 11 years
    I'm now feeling incredibly stupid for not getting that part, too. Thanks for the update!