0

I have a shell script for getting data from some servers, in ~/.bin/shellScript :

OLD="$(curl --silent http://someServer:12345/stats.json | json someKey)"
NEW="$(curl --silent http://otherServer:12345/stats.json | json someKey")

echo "OLD $OLD - NEW $NEW"

I want to echo the results for running it interactively, but I've been wanting to log the results collected too. So crontab -e, and add */5 * * * * /home/user/.bin/shellScript >> /media/dump/scriptDump.

Running the script interactively works fine - I get OLD 123 - NEW 456, but when I look at what's been running from cron, I get OLD - NEW with no data being grabbed with curl.

4
  • 1
    What if you add the full path of json on json someKey? Crontab doe s work in a limited environment and some paths can be missing, so you need to give it the full of it. Commented Dec 20, 2013 at 10:13
  • It never occurred to me that I needed to fix $PATH in the shellscript (even though I knew that cron had a limited env'). /facepalm Commented Dec 20, 2013 at 10:15
  • Hehe it always happens to all of us, no problem. So does it mean that now it is working to you? Commented Dec 20, 2013 at 10:21
  • 1
    Yeah. If you put that as an answer, I'll accept it. Cheers Commented Dec 20, 2013 at 10:23

1 Answer 1

1

As discovered in the comments, you need to add the full path of json when you are calling it. This is because crontab's limited environment.

So instead of

OLD="$(curl --silent http://someServer:12345/stats.json | json someKey)"
NEW="$(curl --silent http://otherServer:12345/stats.json | json someKey")

it has to be

OLD="$(curl --silent http://someServer:12345/stats.json  | /path/to/json someKey)"
NEW="$(curl --silent http://otherServer:12345/stats.json | /path/to/json someKey)"
                                                           ^^^^^^^^^^^^^

[[Note your second line had ") instead of )"]]


Otherwise, you can also add the json path into crontab, as indicated on How to get CRON to call in the correct paths:

PATH=/usr/local/sbin: ... :/path/of/json
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.