Question

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.

Était-ce utile?

La solution

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top