Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron jobs under mac os 10.6 snow leopard

I'm trying to set up an automated svn commit to run semi-hourly under mac os 10.6, but the crontabs i'm adding to cron don't seem to be valid and/or don't seem to even be looked at by cron. For testing i made a simple crontab and script:

Crontab: */2 * * * * /Users/username/crontest

where username is replaced with my system username, thus pointing to my home directory (and yes, those really are tabs between each value - they aren't faithfully reproduced in the code section)

I'm running a crontab -r first, then running crontab .mycrontab that contains the above line. crontab -l spits out the line above, and running ps -A | grep cron shows /usr/sbin/cron running, which I assume is the cron daemon under mac os x. The /Users/username/crontest script is simply appending a line of text to a text file, as such:

echo "hi" >> /Users/username/crontest.txt

What gives? I'm stumped.

like image 768
jtrim Avatar asked Jan 04 '10 14:01

jtrim


People also ask

How do I see what cron jobs are running on my Mac?

Need to quickly see a list of all cron jobs on a computer? You can easily see all scheduled cron jobs by using the crontab command, and seeing cron data works the same on Mac as well as Linux and most other unix environments too.

Does macOS have cron jobs?

Although launchd is the preferred method in macOS, the cron method still works in macOS as well. cron is a Linux utility that schedules a command or script on your server/computer to run automatically at a specified time and date. A cron job is the scheduled task and it is very useful to automate repetitive tasks.

How do I see all cron jobs?

You can use the cat, crontab and other Linux commands to view, list and display all cron jobs. The cron service searches its spool area (usually /var/spool/cron/crontabs) for crontab files (which are named after user accounts); crontabs found are loaded into memory.

Where is crontab macOS?

In Mac OS X Lion the user crontabs are stored in /var/at/tabs . In the past they were located in /var/cron/tabs . You should use crontab -e to interact with these in general, but knowing the location is useful for when you want to restore them from a backup of your disk, or something similar.


2 Answers

Oops...I was missing the newline character at the end of the cron job. That seems to have fixed it.

like image 83
jtrim Avatar answered Nov 03 '22 19:11

jtrim


Although the preferred method on OS X for running automated jobs is launchd, cron is still supported. Chances are you have a permissions problems with your script; make sure it has execute permission.

Also, */2 means every two minutes, not semi-hourly. Try setting the minutes field with a list of minutes:

0,30    *   *   *   *   /Users/username/crontest

Works for me on 10.6.

like image 26
Ned Deily Avatar answered Nov 03 '22 18:11

Ned Deily