Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > Team MacNN > Start F@H with cron, but not as root?

Start F@H with cron, but not as root?
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 14, 2003, 10:22 PM
 
Is it possible to use cron to start F@H in user space rather than as root?

Basically, I'd like to start F@H using a script that runs every hour. The script would check for an instance of F@H and only start one if one is not currently running. This way I could ensure that F@H started running even if no one was logged in within an hour of the machine starting up.

Is this possible?

thanks,
kman
     
Administrator
Join Date: May 2000
Location: California
Status: Online
Reply With Quote
Mar 14, 2003, 10:27 PM
 
Yes, you can set up crons under any username. Whatever the cron does, will be done under that user, even if that user is currently logged out.
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 14, 2003, 10:36 PM
 
Originally posted by reader50:
Yes, you can set up crons under any username. Whatever the cron does, will be done under that user, even if that user is currently logged out.
Okay, cool. I've never really done much with cron and I've just started learning tcsh scripting, so I am going to need a little help here. Anyone want to give me some pointers?

I can handle the launching portion

cd ~/documents/fold;
./osx-3.24 &

Not much, but like I said, I'm a beginner. I'm not sure how to script the conditional statement to check for a running process. I'm also not entirely clear on setting up cron to run the script every hour.

kman
     
Administrator
Join Date: May 2000
Location: California
Status: Online
Reply With Quote
Mar 15, 2003, 12:15 AM
 
Here's a stab at the crontab format. I have not found a decent crontab definition anywhere, so I'll write one. Anyone with more experience, feel free to post a better definition.

crontab format:
{activation parameters} {command #1} ; {optional command #2} ; {optional command #3} ; {etc, commands end on the line ending}

Example:
* * * * * ./folding
This would cause folding to be launched every minute, from your home folder. Very bad, you would end up with 60 copies running by the end of an hour.

Commands are shell commands. Separate multiple commands with a semicolon ";" and end on the line ending.

Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
- or -
1 2 3 4 5 = specific time tags
- where -
1 = Minute (of hour) to activate [0-59]
2 = Hour (of day) to activate [0-23]
3 = Day (of month) to activate [1-31 ... 29,30,31 may not activate during all months]
4 = Month (of year) to activate [1-12 or 3-letter names "Jan,Feb,Mar"]
5 = Weekday to activate [0-7 or 3-letter names "Mon,Tue,Wed"]

If 3-letter names are used on Month/Weekday instead of numbers, they are case-insensitive. "Mon" and "mON" are equally acceptable. If numbers are used for the weekday, "0" and "7" are both Sunday and are interchangeable.

Time tags are separated by spaces. Do not use spaces within a tag, this will confuse cron. All five tags must be present. They are a logical AND of each other. There is another space between the last time tag and the first command.

A time tag can be a wildcard "*", which means "all". It can be one value, several values, a range, or a fractional range.

Examples for the Hour column:
one value: 8 = execute in the 8 AM hour
multiples: 5,6,9 = execute in the 5, 6, and 9 AM hours
range: 5-8 = execute in each hour between 5-8 AM
fractional: */2 = execute in every other hour. 0 (midnight), 2AM, 4AM, 6AM, etc
fractional range: 3-12/3 = execute in every third hour between 3AM and 12PM: 3AM, 6AM, 9AM, 12PM

Example:
5 */3 * * 1-5 cd "desktop/fold1"; ./fold &
This will launch on the 5-minute mark, every third hour, every day, every month, but only on days of the work week (Mon-Fri). It cd's to the Desktop/Folding folder #1, then launches the launch script in nohup mode so folding will keep running.

Example:
20,50 * * Jan-May,7-12 Mon-Fri cd "desktop/fold4"; ./foldlaunchscript
This will launch on the 20 and 50-minute marks, every hour, every day, every month except June (IT desktop-inspection month), but only on days of the work week (Mon-Fri). It cd's to the Desktop/Folding folder #4 on your Quad-CPU PowerMac, then launches the launch script which checks for already-running instances of Folding before trying to launch another copy.

Example:
@reboot cd "/usr/local/mysql"; ./bin/safe_mysqld &
This will launch on each reboot. It cd's to the proper mysql root folder, then launches mysql with the safe startup script in nohup mode.

Example:
12 * * * * cd "desktop/fold2"; ./foldlaunchscript
This will launch on the 12-minute mark, every hour, every day, every month, every day of the week. It cd's to the Desktop/Folding folder #2, then launches the launch script which checks for already-running instances of Folding before trying to launch another copy.

Example:
1 10 13 * 5 ./hiddenfolder/jokescript
This will launch at 10:01 AM, on any Friday the 13th. It launches your virus script.

A special prefix (@AppleNotOnBattery ) can be added to the command line to only execute if the laptop is running on external power - desktops are always plugged in when running, so a desktop will always execute the command. This is an Apple extension, so it only works on Darwin (OSX) systems, not Linux, BSD, or UNIX. I would expect it to work on x86 Darwin, but have no x86 laptop to test it with. Using this command prefix on something that does not support it (like RedHat on a P4) will cause an error.

Example:
45 23 * * * @AppleNotOnBattery ./Applications/Utilities/diskoptimizerscript
This will launch at 11:45 PM each day. It launches a disk optimizer, but only if your laptop is plugged in to a power source.
(Last edited by reader50; Dec 25, 2003 at 03:29 PM. )
     
Forum Regular
Join Date: Nov 2002
Location: Santa Barbara CA
Status: Offline
Reply With Quote
Mar 15, 2003, 01:52 AM
 
Nice explanation of cron by reader50.

Here is what I think you need in your cron and a script that it calls.

cron script:

@reboot cd ~/documents/fold;./osx-3.24 #always start after reboot

* 1-23 * * * cd ~/documents/fold;./checkFold #check status every hour


You should use cron to call a script that actually checks the folding status.


checkFold script:

#!/bin/sh

lineCount=1 #makes a numeric variable
lineCount=`ps ax | grep -c osx-3.24`

if [ lineCount = 1 ];then
cd ~/documents/fold
./osx-3.24 &
fi


The ps ax outputs all the running processes, then the grep -c outputs how many lines have osx-3.24. The ps command itself counts as a process with osx-3.24 in it so there will always be at least one. If there is only one then folding is not happening so it needs to be started. I don't really get how variables and if statements work in shell scripts, I just fiddle around until it seems to work.

After you edit your checkFold script you will need to run:

chmod 755 checkFold

so it will be executable. One thing that I would do is change "osx-3.24" to something like "folding". Otherwise when osx-3.25 comes out you will have to change your script.
     
Administrator
Join Date: May 2000
Location: California
Status: Online
Reply With Quote
Mar 15, 2003, 03:38 AM
 
14 2 29 8 5 ./skynet
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 15, 2003, 09:36 AM
 
Thanks guys! I now have f@h starting at reboot with '&' flag so it continues to run regardless of whether or not anyone is logged in. In the process I also learned a bit about cron. For instance, I had no idea that I could use the @reboot time flag. It suits my needs perfectly and there was no need to try to launch every hour.

Here's my current f@h setup:
G4/867
iBook 700
G4 1Gx2
4 PCs of various sorts

Since I just started this week I have yet to finish a WU, but I'm looking forward to it!

kman
     
Mac Elite
Join Date: Jan 2002
Location: Mile High City
Status: Offline
Reply With Quote
Mar 15, 2003, 12:56 PM
 
Welcome aboard and glad you got it all figured out.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2