Running in the Background with a Root Crontab

Questions and Answers : Macintosh : Running in the Background with a Root Crontab
Message board moderation

To post messages, you must log in.

AuthorMessage
Profile M A Cochran
Avatar

Send message
Joined: 7 Jan 04
Posts: 6
Credit: 59,390
RAC: 0
United States
Message 20138 - Posted: 31 Aug 2004, 1:51:16 UTC
Last modified: 31 Aug 2004, 2:21:37 UTC

I just thought I'd share how I keep SETI@Home running whenever the machine is on via a crontab owned by the root user.

1. If you haven't done so already, log in as a user with administrator permissions and "enable root user" via NetInfo Manager (in /Applications/Utilities). After launching NetInfo Manager, if the 'lock' icon is closed at the bottom of the window, click on it and type your administrator password. When unlocked, the options in the 'Security' menu will be available. If "Enable Root User" is shown, select it. If "Disable Root User" is shown, and you don't know what the Root password is, select "Change Root Password" (and record it somewhere). Relock the window and quit NetInfo Manager. Armed with root capability, you're now master of all domains on your machine, but be careful how you exploit this power, as things could go very awry in a hurry.

2. Launch Terminal and type
su root {CR}
and enter the root password. Make your Terminal window bigger if necessary so you can work without lines wrapping.

3. Type
crontab -e {CR}
This should result in the vi editor opening in the Terminal window. Don't be intimidated! Here are the vi commands you may need to enter your script:
arrow keys navigate around the file.
i inserts text at the cursor position.
a appends text after the character right of the cursor.
o opens a new line below the cursor line.
O opens a new line above the cursor line.
{esc} cancels a i/a/o/O mode.
x deletes one character right of the cursor.
dd deletes the cursor line.
:w{CR} saves the file.
:q{CR} exits the editor.

4. Type in your cron script. Here is what I have for mine:

MAILTO = ""
#
# boinc 4.05
5,25,45 * * * * cd /Applications/SETI/boinc/; cp boinc.log.txt boinc.log.bak; grep 'Finished upload' boinc.log.txt > completed.log.txt; ./boinc_4.05 >> boinc.log.txt
#
# seti classic
15,35,55 * * * * cd /Applications/SETI/setiathome/; ./setiathome_3.03 > /dev/null 2> /dev/null

Comment lines start with a pound sign (#). The numbers before the four asterisks represent at what minutes of every hour you want the script to run. Don't use spaces. The text after the asterisks is the commands to be executed, just like you might type them in Terminal. Separate commands with a semicolon. All commands should be on a single line with no line breaks. Because it's a Mac, copy/cut/paste works in the vi editor; make sure you're in a text insertion mode (i/a/o/O) to paste into vi and {esc} afterwards.

5. Save your script and exit the editor by typing
:wq {CR}
The O/S will install the script in the cron for the root user.

*************************************************************
Now that we've gone through the vi editor thing, here's a shortcut: you can replace a crontab with the contents of a text file by typing

crontab myfile {CR}

Make sure that myfile is saved in "unix mode" (vs. Mac mode) with respect to line feeds/carriage returns. You can do this easily in BBEdit. Also note that this method totally replaces the existing crontab with the contents of myfile.
*************************************************************

6. To verify that the script got installed OK, type
crontab -l {CR} {that's an el, like in lollypop}

7. Type
exit {CR}
to log out of the root user, and then quit Terminal if you want.

===================
NOTES ON MY CRONTAB
===================
-- While the kinks with Boinc are being worked out, I am running both Boinc and SETI Classic, as you can see from the script. This causes no problems (other than increasing the clock time needed to process a workunit if both are running).
-- I accumulate Boinc output to the file "boinc.log.txt" and back it up each time the crontab executes. So that the Boinc command line doesn't fail the first time it executes, create an empty text file named "boinc.log.txt" and put it in the Boinc folder before creating the crontab.
-- I also keep track of the workunits I've completed and sent back to SETI by using grep to examine "boinc.log.txt" for lines with the string 'Finished upload' and recording them in the file "completed.log.txt".
-- You can have the crontab execute as often or as infrequently as you wish by modifying the beginning of the command lines. There's really not much penalty for doing it fairly often, since Boinc manages communications with SETI. I avoided 0 and 30 to miss the likely bombardment of SETI at the top and bottom of the hours by other crontabs out there when we restart our machines and have to wait for the crontab to kick off.
-- You can edit your root crontab anytime you want to make changes. You can also have crontabs for any/all users by just logging in normally as user X and building a personal crontab for some purpose, but these crontabs will only be active when that user is logged in. Root is always logged in.

Your comments are welcome.

Hope this helps,
Mark
ID: 20138 · Report as offensive
davygravy

Send message
Joined: 31 Jan 02
Posts: 24
Credit: 133,388
RAC: 0
United States
Message 20629 - Posted: 31 Aug 2004, 22:43:41 UTC

Hi Mark,

That is great...very thorough.

I have set up my crontab manually before, but when I found things like CronniX, I started to forget how to set up everything the way you show it.

All nice touches, especially the logging.

I was wondering about

MAILTO=" "

...does that suppress unnecessary email messages?


I'll try this all.

Thanks,

davygravy
ID: 20629 · Report as offensive
Profile M A Cochran
Avatar

Send message
Joined: 7 Jan 04
Posts: 6
Credit: 59,390
RAC: 0
United States
Message 20811 - Posted: 1 Sep 2004, 6:20:20 UTC - in response to Message 20629.  

> I was wondering about
>
> MAILTO=" "
>
> ...does that suppress unnecessary email messages?
>
>
davygravy:

The null assignment to MAILTO is there just in case some process wants to mail output rather than just displaying it (screen or into a file with redirection (>,>>)). Usually this might occur with a system-generated message, such as a crash or an abnormal process exit. I did not have much accumulated in my system mail log over the past 2+ years, but why have anything at all?

Thanks for your comments.

Mark
ID: 20811 · Report as offensive

Questions and Answers : Macintosh : Running in the Background with a Root Crontab


 
©2024 University of California
 
SETI@home and Astropulse are funded by grants from the National Science Foundation, NASA, and donations from SETI@home volunteers. AstroPulse is funded in part by the NSF through grant AST-0307956.