Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Understanding OS X's cron



Juan Manuel Palacios writes:

> Hello listers. Here I am again with my backup chores
> novel, this time
> trying to implement the final stages in order to commit everything to
> the main server. A few days ago I posted a script that I want to
> execute daily off of cron but I'm having some problems understanding
> how OS X deals with that last player. According to the man pages OS X
> uses Vixie Cron, with user crontabs located in
> /var/cron/tabs/ and the
> main crontab file living in /etc/crontab. According to cron(8) the
> format of /etc/crontab is different from that used in the users'
> crontabs (it includes a user field), so I am assuming I
> should stick to
> the latter, right?

It's really up to you how you want to do it. You can edit /etc/crontab,
or place your own scripts in /etc/periodic/(daily|weekly|monthly) that
will be run as root by cron at the specified intervals.

> That was installed through "crontab -e" from my admin
> account, which
> means the command will be executed by user "juan". What if I
> wanted it
> to execute as root? Will the following:
>
> crontab -u root -e
>
> let me edit and install a crontab for root, so that the appropriate
> command executes with super powers? Is this advised?

If you run 'sudo crontab -e', that will create/edit root's crontab.
Normal users (even those with sudo access) cannot edit others' crontabs;
only root can do that.

> Currently, despite
> the existence of /etc/crontab (which lists "root" as the user to
> execute the periodic commands), "sudo crontab -lu root" says
> there's no
> crontab for root. Is this to be expected if we consider that
> /etc/crontab doesn't precisely belong to root?

Yes. /etc/crontab is not a "normal" user crontab.

> Should I fix
> the absence
> of the "allow" and "deny" files? Do they have a particular syntax or
> just a line by line list of users?
>
> What does the "MAILTO" declaration exactly do?

It dictates where the standard error and output from the job are mailed
to. If there's no output from the job, there's no mail.

> Boy, this email is full of questions! The last one...
> ones... how does
> cron handle the "SHELL" declaration? My script has an sh shebang
> (#!/bin/sh), will that conflict in any way with the
> declaration, like a
> double call to sh or something like that? Does the shebang override
> "SHELL"? What if I wanted to run a perl script or a tcsh one with the
> appropriate shebangs?

Yes, it's effectively a shell within a shell. No big deal. If you use
#!/usr/bin/perl, it's a Perl script within a shell. Also no big deal.
It works like you think it would.

--Michael
_______________________________________________
macos-x-server mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macos-x-server
Do not post admin requests to the list. They will be ignored.

References: 
 >Understanding OS X's cron (From: Juan Manuel Palacios <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.