0

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?

Filipiz
  • 117
  • 1
  • 2
  • I saw this: http://nixcraft.com/all-about-freebsd-openbsd-netbsd/14900-curl-doesnt-work-crontab.html ... I ran "which curl" which returned "/usr/bin/curl" and updated my script using the full path or curl and still didnt work. – Filipiz Mar 21 '13 at 15:10
  • 1
    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](http://superuser.com) but please [search](http://superuser.com/search) their site for similar questions that may already have the answer you're looking for. – Dennis Kaarsemaker Mar 28 '13 at 00:36

3 Answers3

1

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.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
  • 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! – Filipiz Mar 21 '13 at 15:25
  • I'm now feeling incredibly stupid for not getting that part, too. Thanks for the update! – Jenny D Mar 21 '13 at 16:05
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.

0

I solved the problem.

Cron got lost on file directory reference.

When I changed

curl http://lab.nextt.com.br/somefile1.html -z ../public_html/somefile1.html -o ../public_html/somefile1.html --silent --show-error --location

to

curl http://lab.nextt.com.br/somefile1.html -z /home/user/public_html/somefile1.html -o /home/user/public_html/somefile1.html --silent --show-error --location

it worked.

I'll let this here to anybody who can have this kind of problem in the future.

Filipiz
  • 117
  • 1
  • 2