My script (status.sh) is:
#!/bin/bash
SITE=http://www.example.org/
STATUS=$(/usr/bin/curl -s -o /dev/null -I -w "%{http_code}" $SITE)
if [ $STATUS -eq 200 ]
then
echo $STATUS >> /home/myuser/mysite-up.log
else
echo $STATUS >> /home/myuser/mysite-down.log
fi
I run:
$ chmod +x /home/myuser/status.sh
Then on my crontab i got:
* * * * * /home/myuser/status.sh
When I run:
$ /home/myuser/status.sh
The file /home/myuser/mysite-up.log contains:
200
But when cron run, the file /home/myuser/mysite-up.log contains:
000
What I am doing wrong?
EDIT: I modified the script adding:
set -x
as @Sobrique suggested and I the output is:
SITE=http://www.example.org/
/usr/bin/curl -s -o /dev/null -I -w '%{http_code}' http://www.example.org/
STATUS=000
'[' 000 -eq 200 ']'
echo 000
set -xto your script - it should generate output (and thus an email) of what's going on when it's running (including variable values). I can't see any environment variable or path differences which is the usual problem withcron.-eq) whereas your script as executed appears to test for inequality (-ne)http_proxyset in your normal environment? Is it set in your cron job?