Hi,
Recently I wrote a script to check when a product was available on a web site - basically: wget web page, grep for 'out of stock', if text not found email me to let me know.
Being new to crontabs I did not realize users had their own, I only knew about root's crontab. So I added a line to root's crontab to run my script every hour during office hours. The script ran fine except the logging did not take place - here's what happened:
Code:
# snip...
LogFile="/home/user/Scripts/logs/check-web-page-for-text.log"
DateTimeStampStart=`date +%Y-%m-%d-%H-%M`
echo "Starting $ScriptName at: $DateTimeStampStart" >> $LogFile
echo "Wget url: $UrlAddress" >> $LogFile
echo "Saving url as: $SaveUrlAs" >> $LogFile
# ...snip
Both the log file and the script where owned by my username, not by root, but despite using the full path for the log file no log entries were made in it at all (despite all aspects of my code making log entries as demonstrated by the examples above).
When I realized each user could have their own crontab, I deleted the line which ran my script from root's crontab, and added it to my username's crontab instead. At this point the logging all worked perfectly. Problem solved.
However -I'm always trying to further my understanding of Linux- I would like to understand why the logging did not work when the script was run from root's crontab. Can someone explain why to me please.
Many thanks.