Re: [Hampshire] Cron script problem

Top Page

Reply to this message
Author: John Cooper
Date:  
To: lug, Hampshire LUG Discussion List
Subject: Re: [Hampshire] Cron script problem
On 05/10/10 18:25, Vic wrote:
>
>> So my first question is, where should these 5 scripts reside (they
>> currently live in a folder called backup in the root of the file sytem)
>
> Wherever you like. Just make sure you tell cron the full pathname to the
> script = "./day1" is unlikely to work, because that means "the day1 script
> in the current directory", and your current directory might not be what
> you want it to be...
>
>> How do I get cron to run them and where do I find any logs files that may
>> point to what is going wrong?
>
> Check root's email. cron can mail anyone you tell it to, but if you
> haven't specified someone (and I doubt that you have), root tends to get
> the reports.
>


To add to Vic's comments, the script can be anywhere but if you are
running it from root cron, it must be owned by root and not world
writable. Otherwise, anyone could modify the script and it would then
run as root, opening all kinds of security risks. /usr/local/bin is a
good place for root owned cron scripts. If you are running from your own
account, the script can be anywhere but only writable by you. Check
/etc/cron.allow and /etc/cron.deny don't exist, or if they do your
account is in /etc/cron.allow.

Make sure crond is running.

  $ ps ax | grep cron
  1950 ?        Ss     0:00 crond


I normally change /etc/aliases root: line to my account

# Person who should get root's mail
root:           user1


and then run newaliases commands to make it live (creates the binary
database). You will then get any output from the cron jobs as an email.
If the cron doesn't output anything, you won't get an email. So you
could put in the cron script :-

echo "Start of cron myjob"

and this will be emailed to root (aliased to you) when the cron runs.

You could also run logger and tail /var/log/messages

logger -t mycron1 start of cron


tail -f /var/log/messages

Oct 5 18:45:36 myserver mycron1: start of cron


John.
--
--------------------------------------------------------------
Discover Linux - Open Source Solutions to Business and Schools
http://discoverlinux.co.uk
--------------------------------------------------------------