Closed chivakaa closed 5 years ago
Hey chivakaa,
Thanks for your complement and interest in the project.
I'm looking at your suggestion and wondering if the best route is to implement your auto-discovery, or to simply set those paths to variables at the top of the script.
If I implement auto-discovery, I'm using binaries to do it (which and awk in your example)
Is there a reason a system's cron can't find curl, but can find awk or which?
This solution needs to work for everyone.
Thanks in advance for any more thoughts you have on this.
Hi Sean,
Running script from cron could fail if cron does not load PATH environments where commands / binaries are placed. For instance my root cron has these environments:
HOME=/root LOGNAME=root PATH=/usr/bin:/bin LANG=en_GB.UTF-8 SHELL=/bin/sh PWD=/root
and because of that some commands are not found and scripts without absolute path can fail. From my point of view at least two possible options to solve the issue:
I hope these info can helps!
Hi Sean,
I am wondered with your solution! Just one thing, when i execute locally the script 'route53-ddns-client.sh' works fine, but when i shedule on root crontab, variable 'myPublicIP' don't assign propper values:
get public IP from reflector to generate hash &/or set IP
myPublicIP=$(curl -q --$ipVersion -s -H "x-api-key: $apiKey" "$myAPIURL?mode=get" | jq -r '.return_message //empty')
And the script fails: [ -z "$myIp" ] && fail "Couldn't find your public IP"
Because root cron does not load env for 'curl' or 'jq'. You need to add absolute paths for each command. Absolute paths can be different for each OS.
Also maybe packages 'curl' or 'jq' are not present and system fails. Is recomended add some control code like this:
Define curl binaries path
if which curl | grep '\/curl' >/dev/null 2>&1 then printf "=== Found curl command\n" curl_path=
which curl | awk '{print $1}'
else printf "==== Missing curl command\n" exit 1 fi 2>/dev/nullDefine jq binaries path
if which jq | grep '\/jq' >/dev/null 2>&1 then printf "=== Found jq command\n" jq_path=
which jq | awk '{print $1}'
else printf "==== Missing jq command\n" exit 1 fi 2>/dev/nullAnd remplace all 'curl' calls for variable $curl_path. The same for 'jq' command.