This discussion is locked
Drake Bradley

Q: running background maintenance tasks

The document http://docs.info.apple.com/article.html?artnum=107388 describes the maintenance tasks normally performed between 3:15 am and 5:30 am. If the computer is not left on at night or if it is put to sleep by the energy saver, then these tasks can't occur. The tasks can be done manually for 10.2 or later by using the terminal to enter:

sudo periodic daily [or weekly, or monthly]

Now, suppose one puts the computer to sleep every night so these tasks can't run automatically, and suppose one doesn't perform them manually either. After a month has gone by, the machine is left on all night and sleep mode is deactivated in the energy saver preference pane. Presumably background maintenance tasks will now be performed by OS X between 3:15 am and 5:30 am. My question is this: will the maintenance performed include all three categories (daily, weekly, monthly)? Or just the daily (or possibly the monthly)? Hopefully all three categories would be performed just as if one had entered the terminal and typed:

sudo periodic daily
sudo periodic weekly
sudo periodic monthly

I guess another way to put the question is: Do the monthly maintenance tasks automatically include the weekly and daily tasks as well (if they need to be done), or are they an entirely unique set?

TIA,

Drake Bradley
(from a very wet Whidbey Island)

iMac PowerPC G4, Mac OS X (10.2.x)

Posted on Feb 2, 2006 4:44 PM

Close

Q: running background maintenance tasks

  • All replies
  • Helpful answers

Page 1 Next
  • by Kappy,Helpful

    Kappy Kappy Feb 2, 2006 6:52 PM in response to Drake Bradley
    Level 10 (271,755 points)
    Desktops
    Feb 2, 2006 6:52 PM in response to Drake Bradley
    Each is a separate cron schedule that executes separate shell scripts. The OS saves a file that each maintenance script checks to find out when it was last executed and executes the script only if the established time has elapsed.

    However, a better method is to purchase and install the shareware utility called Macaroni (www.versiontracker.com) which will check as soon as the computer is turned on or waked up to see if the maintenance scripts have been run. If they have not been run on schedule, Macaroni will automatically run the maintenance script. In this way the maintenance will be done on schedule whether the computer is on 24/7 or not.
  • by roam,Helpful

    roam roam Feb 2, 2006 9:53 PM in response to Drake Bradley
    Level 6 (13,576 points)
    Feb 2, 2006 9:53 PM in response to Drake Bradley
    Hi Drake,
    Daily will run every 'night' at 3:15 am
    Weekly will run every Saturday morning at 4:30 am, and
    Monthly will run on the first of the every month at 5:30 am., but they all are run seperately, so you might get two but usually not all three at once unless it happens to be Saturday the first.
    However you can manually run them all from Terminal at any time, ( you need to establish root access for this) .

    roam.
  • by Drake Bradley,

    Drake Bradley Drake Bradley Feb 3, 2006 10:33 AM in response to Drake Bradley
    Level 1 (90 points)
    Feb 3, 2006 10:33 AM in response to Drake Bradley
    Kappy and Roam,

    Thanks for the info. I have read up a bit on sudo, and feel that it is probably best that I don't muck around there too much. However, one post seemed to indicate that all three maintenance scripts could be executed by entering:

    sudo periodic daily weekly monthly

    As I understand it, this would force all three tasks to be performed regardless of the last time they had been done. However, Kappy's comment above states that the "OS saves a file that each maintenance script checks to find out when it was last executed and executes the script only if the established time has elapsed." If that applies to the sudo command (as well as background maintenance at night), then if I enter the command one minute before the appropriate time interval (say, a week) had elapsed, it wouldn't run at all. Is that actually the case? Does the output of the sudo command indicate whether the script was actually run or not?

    Thanks,

    Drake
  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Feb 3, 2006 12:16 PM in response to Drake Bradley
    Level 5 (4,649 points)
    Feb 3, 2006 12:16 PM in response to Drake Bradley
    Drake,

    Let me try to clear up the confusion. When you start up your computer the OS starts the cron daemon. A daemon is a small application that runs in the backround. cron is a scheduler. cron looks for preference files called crontab. crontab tells cron when to run applications or scripts. Users may have a crontab and the system has a crontab located in the /etc directory. cron loads the information in the crontab file into memory. The cron daemon wakes every minute checking the time then it will run the instructions from crontab if the time is appropriate.
  • by Drake Bradley,

    Drake Bradley Drake Bradley Feb 3, 2006 12:30 PM in response to Mark Jalbert
    Level 1 (90 points)
    Feb 3, 2006 12:30 PM in response to Mark Jalbert
    The cron daemon wakes every
    minute checking the time then it will run the
    instructions from crontab if the time is appropriate.


    Mark,

    This is useful to know, and perhaps explains the occasions when my iMac seems to start disk I/O even when I have not done anything with apps that require that (or even if no apps are running).

    But this still doesn't answer my question. If the computer is always in sleep mode over night (as it is) then the iMac is not awake at the "appropriate" times for the cron maintenance tasks scheduled to run from 3:15-5:30 am. So I want to run these tasks manually with sudo -- but if I do, will they actually execute if the usual time for the task (a day, a week, a month) has not expired yet since the last execution of that task? (See Kappy's comment above.) If the answer is no, then I will need to maintain a careful log of when I have done each task.

    Drake
  • by nifflerX,

    nifflerX nifflerX Feb 3, 2006 1:01 PM in response to Drake Bradley
    Level 4 (2,814 points)
    Feb 3, 2006 1:01 PM in response to Drake Bradley
    Just use anacron. It checks your cronjobs every minute and makes sure they run at an appropriate time. So, if your computer is asleep at 3:15 and can't run the daily cronjob, anacron (once your computer wakes up) will realize that it's been 24 hrs since the daily cronjob has run and run the daily cronjob. HTH.


    -NifflerX

    iBook G3   Mac OS X (10.3.9)  
  • by Drake Bradley,

    Drake Bradley Drake Bradley Feb 3, 2006 1:21 PM in response to nifflerX
    Level 1 (90 points)
    Feb 3, 2006 1:21 PM in response to nifflerX
    So, if your
    computer is asleep at 3:15 and can't run the daily
    cronjob, anacron (once your computer wakes up) will
    realize that it's been 24 hrs since the daily cronjob
    has run and run the daily cronjob. HTH.


    NifflerX,

    Thanks, but this is not what I want. Usually when I start my computer up I want to use if for something and prefer not to compete with system routines doing basic maintenance. When I'm ready to break for lunch, say, then I might want to run a maintenance process manually, since I will be away from the machine anyway.

    I know there is 3rd party-software to do this, but I'd prefer to avoid adding yet more software to worry about updating, having conflicts, etc. That is why sudo is attractive.

    Still, nobody answered the question I posed above. If I run the process when I choose using sudo, and the usual time interval has not elapsed (day, week, month) since the task was last done, will it actually perform the task or not?

    If not, then I will need to keep a careful record of when I run each task manually, and then when the appropriate time has passed (but not before), run it again.

    If yes, then I don't need to worry about keeping a precise log -- I can just run sudo whenever I feel like it and be sure all the tasks have in fact been performed.

    Drake
  • by Kappy,

    Kappy Kappy Feb 3, 2006 1:30 PM in response to Drake Bradley
    Level 10 (271,755 points)
    Desktops
    Feb 3, 2006 1:30 PM in response to Drake Bradley
    I'm afraid you still don't quite understand. The periodic maintenance tasks are scheduled via a crontask. They are run automatically at a specific time regardless if you run them manually. However, each task produces a log.out file that says when it was last run. This information is also put in the system logs. If you manually run one of the periodic tasks one minute prior to a scheduled time, then it will simply run itself again when the scheduled time arrives. However, if the computer is turned off or is asleep at the scheduled runtime, then obviously the script will not be exeuted.

    A utility such as Macaroni can take advantage of that information to detect if the script was run at its scheduled time, and if not run it automatically.
  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Feb 3, 2006 1:33 PM in response to Drake Bradley
    Level 5 (4,649 points)
    Feb 3, 2006 1:33 PM in response to Drake Bradley
    To answer you question, yes. If you manually run the scripts they run. Kappy's post is a bit misguided. The scripts do not check when they were last run. cron is the big boss. Let me explain futher. periodic is a shell script that runs any scripts in the daily, weekly, or monthly directories. periodic maintains its own log files- /var/log/daily.out, /var/log/weekly.out and /var/log/monthly.out. So, you could consult the modification date of these files to check the last time the scripts were run.

    I recommend that you not run all three scripts in succession. At best run them as intended or run the scripts less frequently. You could even forget about the one script in the weekly directory unless you use locate or whatis in the Terminal application.
  • by nifflerX,

    nifflerX nifflerX Feb 3, 2006 1:40 PM in response to Drake Bradley
    Level 4 (2,814 points)
    Feb 3, 2006 1:40 PM in response to Drake Bradley
    Drake Bradley,

    You might be able to use anacron to your advantage here. Anacron does not run the tasks at the specified time, 3:15, 4:30 and 5:30. Instead it comments those out and keeps track for itself when the scripts are run. If you run the scripts by hand the timestamp will be updated and the scripts won't be run again until the appropriate time.

    For example, say your daily script was set to run at 3:15 as normal. You have anacron installed and then run 'sudo periodic daily' at 8:15. The timestamp has now been updated and the anacron won't bother to run the daily cronjob again until 8:15 the next day.

    One thing to note though, anacron checks every single minute as to whether or not the cronjobs should be run. This does not take much processing power, but it does take a small amount.

    HTH.

    -NifflerX
  • by Kappy,

    Kappy Kappy Feb 3, 2006 1:44 PM in response to Mark Jalbert
    Level 10 (271,755 points)
    Desktops
    Feb 3, 2006 1:44 PM in response to Mark Jalbert
    Mark,

    See my immediately prior post which, I believe, states the situation correctly.
  • by Drake Bradley,

    Drake Bradley Drake Bradley Feb 3, 2006 1:50 PM in response to Kappy
    Level 1 (90 points)
    Feb 3, 2006 1:50 PM in response to Kappy
    Kappy,

    I'm afraid you still don't quite understand.


    Got that right.

    The
    periodic maintenance tasks are scheduled via a
    crontask. They are run automatically at a specific
    time regardless if you run them manually.
    However,
    each task produces a log.out file that says when it
    was last run. This information is also put in the
    system logs. If you manually run one of the periodic
    tasks one minute prior to a scheduled time, then it
    will simply run itself again when the scheduled time
    arrives.
    However, if the computer is turned off or
    is asleep at the scheduled runtime, then obviously
    the script will not be exeuted.


    It is clear from this that manually running a maintenance task with sudo does not prevent it from running again (unnecessarily?) if the computer is on at the next scheduled time for the task, even if that is only a few minutes after the task was executed manually.

    On the other hand, if the computer is never on at the time normally scheduled for the task, and one uses sudu to perform the task manually, and if this is done before the usual interval employed by the automatic process, will it still perform the task? I thought this was a simple question. Apparently not. Suppose I enter

    sudo periodic monthly

    today, and suppose that it actually does whatever it is supposed to do during the normal (automatic) maintenance for the month.

    Now, on the next day, I again enter

    sudo periodic monthly

    Is the task executed again, or does the OS know that I manually executed it the day before, and there is no need for it yet?

    Note that this question has nothing to do with the automatic maintenance that would normally occur if I left the machine on 24/7.

    Drake
  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Feb 3, 2006 1:52 PM in response to Kappy
    Level 5 (4,649 points)
    Feb 3, 2006 1:52 PM in response to Kappy
    Ya Kappy,

    I was referring to your first post. I'll edit mine if I still can.
  • by Drake Bradley,

    Drake Bradley Drake Bradley Feb 3, 2006 2:06 PM in response to Mark Jalbert
    Level 1 (90 points)
    Feb 3, 2006 2:06 PM in response to Mark Jalbert
    Mark,

    To answer you question, yes. If you manually run the
    scripts they run.


    THANK YOU! For a simple answer to a simple (?) question.

    I recommend that you not run all three scripts in
    succession. At best run them as intended or run the
    scripts less frequently. You could even forget about
    the one script in the weekly directory unless you use
    locate or whatis in the Terminal application.


    Thanks, I will follow your advice.

    At this point, another alternative I am considering is to just leave the computer on all night on the evening preceding the 1st of every month so that the monthly maintenance gets done automatically at 5:30 am (see Roam's post). Presumably, daily and weekly scripts would run as well, under the direction of OS. Will this create the problems you allude to above when doing all three tasks simultaneously with sudo?

    And is it a big deal not to do the daily's every day?

    Thanks for the help!

    Drake
Page 1 Next