Cron won't run!

Discussion in 'macOS' started by Mechcozmo, May 3, 2006.

  1. Mechcozmo macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #1
    At least, I think so. My server's system crontab doesn't seem to be happy doing much of anything. It is currently set up to run a shell script, another perl script, a command to perform a chmod, and the 'test' one: make a folder.

    The make a folder script runs every minute. The 'who' column says that root is the owner. And the command is a simple 'mkdir WORKALREADY'
    But there is no "WORKALREADY" folder being made in my home directory. :mad:

    This is not very good, as the shell script bans hackers to my server (runs every 5 minutes), the perl script generates usage logs (Every Saturday), and the chmod command keeps the /Library/Webserver/Documents folder at a state of permissions so that whatever is uploaded to the webserver will be allowed to display (every 5 minutes).

    What is wrong with my crontab?:(
     
  2. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #2
    Wouldn't the folder be created in root's home directory (unless you are logged in as root)? Try 'mkdir /Users/<user name>/WORKALREADY'.

    Or better yet, try 'open /Applications/iCal' or something. Much easer to check to see if it worked.
     
  3. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #3
    Did you edit the cron file using the crontab command, or by editing the file directly?

    If it's the latter, perhaps cron just didn't notice you changed its instructions. You should be able to kickstart cron into noticing by using the "crontab -e" command as root to edit it again (even if you just change a comment), or with the "touch /etc/crontab" command as root, or even by restarting your Mac.
     
  4. cjc343 macrumors 6502

    Joined:
    Jan 6, 2004
    Location:
    In the apple store, in front of a G5.
    #4
    For some reason (that I never investigated) cron doesn't seem to actually execute any jobs by default. Stuff that used to be in crontab (I think...) has been moved to /System/Library/LaunchDaemons

    The things I wanted to add were weekly and monthly things, so it was easier for me to edit those scripts to do what I wanted.

    Sorry I can't be of more help than telling you something you already know...
     
  5. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #5
    Apple doesn't use cron anymore. Everything they put in cron now does launch from Launch. But cron is still there. I use it everyday for clean up and shut down at my lab. It am 100% certain it still works.
     
  6. dr_lha macrumors 68000

    Joined:
    Oct 8, 2003
    #6
    It does. I have cron jobs running on my Tiger system right now. I set up stuff with launchd as well using the excellent "Lingon", but I find cron quicker and easier to set up as I'm familiar with it.
     
  7. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #7
    That is how I feel. I've tried to quickly learn launchd, but with no success. I just say "screw it, I'll use cron." I am fearful that the next version of OS X will no longer have cron and I'll be forced to use launchd.
     
  8. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #8
    I edited the file directly. I can't figure out the crontab command, but the file is simple enough. I tried the 'touch /etc/crontab' command but that didn't seem to help at all.

    You're right... I edited the command to make the folder at the root level of the drive. No go.

    I'm trying a restart to see if that will help.
     
  9. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #9
    I changed the make-folder command to the open-iCal command. Nothing.
    I restarted. Got Chicken of the VNC a bit mad, but whatever. And after a minute...

    Nothing. :mad:

    To prove I'm not going insane, I present this:

    Code:
    # The periodic and atrun jobs have moved to launchd jobs
    # See /System/Library/LaunchDaemons
    #
    # minute        hour    mday    month   wday    who     command
    5       *       *       *       *       root    sh /Users/admin/Documents/Scripts/FTPd-autoban.sh
    0       0       *       *       6       root    /usr/local/bin/purestats -m -d -f -o /Users/admin/Documents/Logs
    5       *       *       *       *       root    sudo chmod -R 664 /Library/Webserver/Documents
    1       *       *       *       *       root    open /applications/ical
    
     
  10. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #10
    I'm not sure about the rest, but try this for iCal instead. Just change the minute.


    Code:
    01      *       *       *       *       root    open /Applications/iCal.app
     
  11. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #11
    You have incorrectly edited the file using a text editor rather than using the crontab -e command. It is not going to work until you go back and use crontab to edit the file.
     
  12. dr_lha macrumors 68000

    Joined:
    Oct 8, 2003
    #12
    You should use "crontab -e" and set the environment variable "EDITOR" to whatever text editor you prefer (otherwise it defaults to vi I believe).

    Also, /etc/crontab is not the root crontab on Tiger I believe. The root crontab is now stored in /var/cron/tabs/root
     
  13. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #13
    Not true. I always use an editor. It always works for me.

    Again, you do not have to use crontab -e. I open up crontab in pico and edit it all the time. It always works.

    No, /etc/crontab is the correct one. I tested it out, and I don't even have a crontab where you suggested.
     
  14. dr_lha macrumors 68000

    Joined:
    Oct 8, 2003
    #14
  15. grapes911 Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #15
    Interesting. I just skimmed it. I'll read it fully later. pico and /etc/crontab has always worked for me and still does. I see no reason for me to change.
     
  16. dr_lha macrumors 68000

    Joined:
    Oct 8, 2003
    #16
    Agreed, it should work. Just given that the guy is having trouble trying that, it can't hurt to use a different method.
     
  17. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #17
    Mechcozmo, I'll chime in.

    I encourage you to read the manual on crontab. man crontab

    To make certain your edits worked, simply use crontab -l and/or sudo crontab -u root -l in Terminal. This will list your current crontab file. DO NOT use sudo crontab without a user option

    If you really don't want to use crontab -e to modify your crontab, then create your own crontab file and call it whatever you like. Do NOT put this in /var.

    Then after you create the file, simply do a sudo crontab -u root /path/to/your/new/file

    Follow this with a sudo crontab -u root -l to make certain it accepted your changes. This will overwrite previous crontabs.

    PS. I haven't ever encountered where you add a username to your crontab. That part seems weird to me. Since every user has their own crontab, it wouldn't make sense to allow the ability to masquerade as a different user. My examples assume you want these to run as root, which is why most of the commands have the -u root option.

    I suggest your the file you create look like this.

    Code:
    5       *       *       *       *       sh /Users/admin/Documents/Scripts/FTPd-autoban.sh
    0       0       *       *       6       /usr/local/bin/purestats -m -d -f -o /Users/admin/Documents/Logs
    5       *       *       *       *       chmod -R 664 /Library/Webserver/Documents
    1       *       *       *       *       open /applications/ical
    
    Then follow the above instructions.


    Finally, if you don't want to hassle with Terminal, there exists some crontab GUIs but I don't have any experience with them to recommend one. Also you may want to consider redirecting output so you can actually see whats going on...

    I think thats about it.

    PPS. Obviously (or maybe not) - if you are logged in as root, you won't need the sudo.

    Feel free to PM me if you need addt'l assistance.
     
  18. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #18
    A question for kingjr3:

    Your example cron file includes the task
    sudo chmod -R 664 /Library/Webserver/Documents​
    Why would you use sudo in a cron file? If it's root's cron file, I would think it wouldn't be necessary, and if it's a mortal user's cron file, I wouldn't think it would work.
     
  19. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #19
    That was Mechcozmo's crontab example.....I didn't really look at it, but yes you are correct. sudo would indeed be redundant if this is root's crontab and impossible in any other user's crontab...good catch Doc. post edited.

    :)
     
  20. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #20
    Code:
    Server-G4:~ admin$ sudo crontab -u root -l
    Password:
    crontab: no crontab for root
    Server-G4:~ admin$
    That would be a bad thing, wouldn't it?
     
  21. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #21
    The root column existed in all the entries already so I thought I should keep them there for my additions...
    And the crontab command is very confusing. I get a bunch of tildes, odd colors, and no clear explanation. Editing the file ought to work and is more clear for me.

    As an addition to my above post; the file exists, but the command says it does not. :confused:
     
  22. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #22
    No. It simply means that user root doesn't yet have a cron file. Since you were asking to display it, not edit it, the command tells you there isn't such a file.
     
  23. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #23
    Except that the root user should have /etc/crontab as its cron file. If I remember the man page correctly.

    However I used the instructions on that Oreillynet.com site to use the 'crontab -e' in nano. Now, I DO have a root crontab. Or so it says.

    Code:
    Server-G4:~ admin$ sudo crontab -e
    crontab: no crontab for root - using an empty one
    crontab: installing new crontab
    Server-G4:~ admin$ sudo crontab -l
    # The periodic and atrun jobs have moved to launchd jobs
    # See /System/Library/LaunchDaemons
    #
    # minute        hour    mday    month   wday    who     command
    5       *       *       *       *       sh /Users/admin/Documents/Scripts/FTPd-autoban.sh
    0       0       *       *       6       /usr/local/bin/purestats -m -d -f -o /Users/admin/Documents/Logs
    5       *       *       *       *       chmod -R 664 /Library/Webserver/Documents
    1       *       *       *       *       open /applications/ical.app
    iCal still isn't opening though... which it should be.

    EDIT: I take that back... iCal opened but a bit late it would seem...
    EDIT v2: VNC, forgot to refresh, I think...
    EDIT v3: No, 'top' says iCal isn't here and it has been 3 minutes...
    EDIT v4: Yeah, it is running the cron scripts but not at their 'correct' times. iCal should have opened 4 times by now but it hasn't, and top doesn't show it as being open. At least I know the scripts will run belatedly...
     
  24. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #24
    I'd be surprised if you could use a command like open /applications/ical.app in a cron file because iCal requires a graphic environment and cron runs as a background process (a daemon).

    Perhaps it would be better, for testing, to start with a command such as touch /Users/Mechcozmo/Documents/test.txt and then see if that file gets created when the cron task is supposed to run.
     
  25. Mechcozmo thread starter macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #25
    The command did work, but delayed. (Not every minute as it was supposed to)

    New and improved crontab using 'sudo crontab -e'
    Code:
    Server-G4:~ admin$ sudo crontab -l
    # The periodic and atrun jobs have moved to launchd jobs
    # See /System/Library/LaunchDaemons
    #
    # minute        hour    mday    month   wday    command
    5       *       *       *       *       sh /Users/admin/Documents/Scripts/FTPd-autoban.sh
    0       0       *       *       6       /usr/local/bin/purestats -m -d -f -o /Users/admin/Documents/Logs
    5       *       *       *       *       chmod -R 664 /Library/Webserver/Documents
    1       *       *       *       *       touch /text.txt
    No 'text.txt' after a minute however; not even after about 5 minutes.
     

Share This Page