LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-27-2011, 06:22 AM   #1
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 27

Rep: Reputation: 0
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...

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.

Last edited by mattst; 10-27-2011 at 06:24 AM.
 
Old 10-27-2011, 07:18 AM   #2
digitaldude
LQ Newbie
 
Registered: Sep 2010
Posts: 20

Rep: Reputation: 0
The user should have write access to the logs.
 
Old 10-27-2011, 07:22 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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?
 
Old 10-27-2011, 08:00 AM   #4
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 27

Original Poster
Rep: Reputation: 0
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
Cheers.
 
Old 10-27-2011, 09:17 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
chmod g+w /home/user/Scripts/logs/check-web-page-for-text.log
 
Old 10-27-2011, 09:25 AM   #6
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 27

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
crontab



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab not running script j8177e5 Linux - Newbie 2 12-21-2010 08:54 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 06:21 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM
error running script on crontab haora Linux - Newbie 3 03-11-2005 04:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration