Thanks again to everyone for all their help with this problem! 

I spent quite a bit of time trying to get cron working properly on OS X so I thought 
I'd share my final solution with everyone and some of the problems I encountered along 
the way.   Sorry if some of this is obvious to folks.  I'd already set the executable 
bit on the build.pl file (chmod +x build.pl)

1) You have to edit the crontab file with the command "crontab [-u userName] -e". If 
you edit it in some text editor, cron won't know to recompile the file.

2) I ended up using the root's crontab instead of 'releasebuilder', the login name for 
all our build machines. You can edit the root's crontab with 'sudo crontab -e', you'll 
then be prompted for the root's password.

3) My crontab entry originally looked like this:

"15 2 * * * releasebuilder perl /Volumes/Builds/Development/build.pl"

I tried a bunch of variations of this line, excluding the username field, making it 
'root', putting the full path to the perl exe (/usr/bin/perl), etc. None of them 
appeared to work right, although some of them succeeded in launching the perl file as 
a background process. The only problem was, since it wasn't running in the terminal 
window, there was no GUI component and no good way to know it's progress except 
redirecting to a log file, etc. 

4) Then to get the perl to run in the Terminal, then tried the following:

"15 2 * * * open -a Terminal.app /Volumes/Builds/Development/build.pl"

The open command has the -a argument to say which app to run the file argument with. I 
tried the usual variations of adding/removing/changing the username field, putting the 
full path to Terminal.app (/Applications/Utilities/Terminal.app), putting the path to 
the actual Terminal exe within the Terminal OS Package 
(/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal) but none of these 
worked either. You can look at /var/log/system.log to see the results of any cron job 
and it looked like the process was launching fine but there was no terminal window 
launching, etc. Finally, I tried quitting the Terminal altogether and then the cron 
job worked perfectly! Of course this still wasn't good because if the Terminal was 
ever launched, the build process would fail to start up.

5) In the end, here's the final solution.

Make an applescript file and save it as a read-only application with the 'don't show 
on startup' checkbox checked. The applescript file looks like this:

"tell application 'Terminal'

run

do script with command "/Volumes/Builds/Development/build.pl"

end tell"

This successfully launches a Terminal window and runs the build.pl file within it, 
even if the Terminal is already running with X number of windows already opened.

Thanks again 

Noah

 

Reply via email to