CRONTAB, user vs. root, execute reboot command

Discussion in 'macOS' started by joecool99, Dec 13, 2009.

  1. joecool99 Suspended

    joecool99

    Joined:
    Aug 20, 2008
    Location:
    USA
    #1
    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
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    You're trying to do two commands with one crontab entry. That won't work.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Try using the shutdown command. It can do reboots as well despite its name. Does anything currently happen when the reboot should be occurring?
     
  4. jzuena macrumors 6502a

    jzuena

    Joined:
    Feb 21, 2007
    Location:
    Lexington, MA, USA
    #4
    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.
     
  5. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #5
    Sure it will. We have hundreds of commands in a couple of application accounts.
     
  6. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #6
    Huh. Didn't know that. Thanks!
     
  7. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #7
    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-
     
  8. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #8
    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-
     
  9. joecool99 thread starter Suspended

    joecool99

    Joined:
    Aug 20, 2008
    Location:
    USA
    #9
    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
     
  10. Don.Key macrumors regular

    Joined:
    Jan 11, 2005
    #10
    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.
     
  11. joecool99 thread starter Suspended

    joecool99

    Joined:
    Aug 20, 2008
    Location:
    USA
    #11

    uh, oh.... that's rater complicated. but i'll try...
    or is there a GUI utility for such ?
     
  12. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #12
    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-
     

Share This Page