Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joecool99

Suspended
Original poster
Aug 20, 2008
726
69
USA
i need to be able to reboot my system every hour. i tried the below:
iCal opens fine as scheduled, but the reboot command doens't.
assume it needs to be executed as root ? how can that be done automatically ?

# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
27 * * * * open -a iCal
30 * * * * reboot
 
Try using the shutdown command. It can do reboots as well despite its name. Does anything currently happen when the reboot should be occurring?
 
i need to be able to reboot my system every hour. i tried the below:
iCal opens fine as scheduled, but the reboot command doens't.
assume it needs to be executed as root ? how can that be done automatically ?

# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
27 * * * * open -a iCal
30 * * * * reboot

I agree that this needs to be in root's crontab.

Maybe: sudo crontab -u root -e

otherwise: sudo su -
then: crontab -e

Then use "shutdown -r now" instead of "reboot" for the command in cron.
 
cron?? Why use that? Do you realize that cron is, for all intents and purposes, deprecated now?

Use launchd instead. Download "Lingon" and make a "USERS DAEMON" that runs every hour and executes this command:

/sbin/shutdown -r now

Much better than running cron on Mac OS X. With "Lingon", it is much easier too.

S-
 
Also, if you want to open iCal then restart, make a shell script file with this line:

/usr/bin/open -a /Applications/iCal.app; /sbin/shutdown -r now

Then call that script from the "USERS DAEMON" you create with "Lingon".

S-
 
/sbin/shutdown -r now
S-

that worked instead of reboot


ps: what i'm actually trying to do now is to shutdown and relaunch application at specific time since it was started.

i've application X that's loaded on the system start. i want it to run for about 50 min, then QUIT and relaunch again.

how can this be done ? it's for a interactive video performance. there is some issue with memory leak that cannot be fixed at the moment so we need to get around it this way.

please help
 
please help

Well, that's easy...

I cannot give you complete solution, it depends in your settings but I will give you the idea / ingredients:

1) Launchd can take care of application, so it is restarted after it crashes
2) 'killall' is a unix shell command which will kill all processes with certain name

Now, you would probably want to:

1) Create a launchd xml service description for your app, use Lingon (link in one of previous posts). Make sure this works and app is indeed started by launchd

2) Learn how to kill this app using killall, you will need exact unix process name of this application. shell command 'ps axu' might be of help. This also will show if (1) actually restarts app once it dies.

3) once you get (2) working reliably create another launchd xml service description for the command you figured out in (2) and make sure this is run once in an hour by launchd.

That's it.

Should be no more then 1-2 hours job.
 
Well, that's easy...

I cannot give you complete solution, it depends in your settings but I will give you the idea / ingredients:

1) Launchd can take care of application, so it is restarted after it crashes
2) 'killall' is a unix shell command which will kill all processes with certain name

Now, you would probably want to:

1) Create a launchd xml service description for your app, use Lingon (link in one of previous posts). Make sure this works and app is indeed started by launchd

2) Learn how to kill this app using killall, you will need exact unix process name of this application. shell command 'ps axu' might be of help. This also will show if (1) actually restarts app once it dies.

3) once you get (2) working reliably create another launchd xml service description for the command you figured out in (2) and make sure this is run once in an hour by launchd.

That's it.

Should be no more then 1-2 hours job.


uh, oh.... that's rater complicated. but i'll try...
or is there a GUI utility for such ?
 
A more elegant way to do this is using AppleScript. Something like:

Code:
tell application "Application Name"
	quit
end tell

delay 2

tell application "Application Name"
	activate
end tell

Then call that script from a shell script using Lingon to make an launchd Agent to run it every 50 minutes.

This easy to do. Look here for some more insights:

http://www.mactipper.com/2008/06/run-applescript-every-day-at-5-am.html

S-
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.