I’ve been experimenting with cronjobs recently and have it setup like so:
crontab:
SHELL=/bin/sh
MAILTO=me@me.com
26 11 * * * wget http://diruser:pass@domain.com/path/to/file.php
Within the php file it runs is a SQL query which at the moment just runs an insert. This works fine and runs the insert but when I look at the email it produces it says this:
email:
wget http://diruser:pass@domain.com/path/to/file.php:
Command failed with exit status 1
I was just wondering if anyone knows why it would return command failed? It obviously doesn’t fail but the email response makes me think I’ve done something wrong somewhere.
Also, is it good practice to put the file the cron is calling inside a password protected directory or is there a better way around it (such as checking that the request ip is that of the server or something).
Most likely,
wgetthrows an error because it cannot save the result. By defaultwgetwill try to store thr result on disk. When running in a cron job, the working directory is (usually)/. You , as a user, probably cannot store a file there.Instead, tell
wgetto drop the result, or pipe it to/dev/null. Fox example: