Root crontab running script, log re-directs fail. Explanation needed.
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... 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. |
The user should have write access to the logs.
|
The redirection looks OK (and running the same script as your username proves it) as long as the log file was writeable for root ... was it?
|
Thanks guys.
I think not - I thought root had 'absolute power' and could read/write/exe to every file - I take it that is not the case then?! Since the machine I am using is a one user PC, would it be sensible to add root to my group (my group name is the same as my username)? That way in future I can allow root access to a file with: Code:
chmod ug+rwx file |
Or, assuming there is a root group and root is in it, you could (as root) change the group of the file to root:
Code:
chgrp root /home/user/Scripts/logs/check-web-page-for-text.log |
Thanks catkin.
I didn't realize that a file's group could be a group that the file owner is not a member of. Cheers. |
All times are GMT -5. The time now is 05:12 PM. |