Using Cron or Launchd

I need to run a file every 15 minutes.
I have never used Cron. Some docs I have found, make it look staight forward.
Could someone give me the basics to set up a cron job?
Is cron running by default on OS X 10.4.x?

If I pico /private/etc/crontab this is what I see:
There are no jobs currently in my cron tab:
# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
#
# minute hour mday month wday who command

Is this where I need to set up me cron job?
Should I use launchd instead?

I can get around in the terminal.
Could someone give me quick lesson on cron, or point me to some Apple docs?
Thank you

Posted on Nov 3, 2005 1:29 PM

Reply
6 replies

Nov 3, 2005 10:57 PM in response to Michael Alatorre1

Thanks for the links!
I managed to get my cron job set up and I can use the Cronnix menu to "Run Now" and it runs my script.
But, my script won't run every minute as shown below. It will only run the script if I use the "Run Now" from Cronnix.

1 * * * * php /Library/WebServer/siteroot/news/admin/script.php

I have set this up as a system cron job and as a user cron job. It acts the same way for each user.
It's as if cron is not checking every minute to see if it needs to run a job.
In 10.4.x is cron on?
I mean, by default is cron activated?

Thanks for any help!

Nov 4, 2005 7:18 PM in response to RGNelson

In crontab syntax:

x/n in range x with frequency n

e.g. */2 in Hour means "every other hour"

So, if you want it to run every minute, put */1 in Minute.

iRC, in 10.4 launchd will automatically start cron if a crontab has an entry. You can check this in the Terminal:

$ ps -ax | grep [c]ron

If I run the above on my home iMac G5 (which has no cron entries), nothing. When I run the same on my Xserve at work (with its cron entries), it results with:

53 ?? Ss 0:01.37 /usr/sbin/cron

So, it's active on my Xserve, and running its cron jobs as specified. HTH

Nov 26, 2005 11:37 PM in response to RGNelson

RG,

The problem may be that when cron runs your task, it doesn't know where to find the php binary. When you log in and use Cronnix to run a task, it uses the path of the logged-in user (or perhaps the default path of the user whose crontab is open; I haven't checked to verify). This will almost certainly be different from the path variable when cron runs the task. If you want to verify that, have a cron job that echoes the path to a file, and run it with both cron and with Cronnix to compare the output. Note that this may vary from system to system.

Shorter version: never assume that the operating system knows the location of a script file or an executable: always include the full path for every element in the filesystem, just as you did with your php script. In this situation, your command should look like this:

/usr/bin/php /Library/WebServer/siteroot/news/admin/script.php

(Assuming that your php binary is in /usr/bin--type which php at the command line if you're not sure.)

David Walton

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using Cron or Launchd

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.