MAGICtricks
return

Modifying unix maintenance times

The material on his page provided by Robert Y Elphick and is based on material in "MAC OS X HACKS" published by O'Reilly.

WARNING This is for geeks!

OS-X runs maintenance during the early hours of the morning when most of us are asleep. Each of these maintenance runs only lasts a minute or two and does not require much CPU. Unfortunately our Macs are also asleep or off so these maintenance never gets performed. The maintenance times can be changed from the strange defaults used by Apple. Here is a set of steps to change the times at which unix performs the regular maintenance.

  1. Start up the terminal
  2. type cd /private/etc and then <return>
  3. type sudo cp crontab crontab.original
  4. you will be asked for the administrator password - type it in
  5. type sudo vi crontab and then <return>
  6. The vi editor should give a screen that looks like this:
  7. use the arrow keys to move the cursor down to the 11th line and is over the "1" and then type r0 (that last key stroke is the number 0, not the letter oh)
  8. move the cursor right over the "5" and then type r2
  9. move the cursor right over the "3" and then type r3
  10. move the cursor left one space and then type r1
  11. move the cursor down one line and left to the "3" and then type r0
  12. move the cursor right over the "0" and then type r4
  13. move the cursor right over the "4" and then type r3
  14. move the cursor left one space and then type r1
  15. move the cursor right over the "6" and then type r* (the last character is <shift>8)
  16. move the cursor down one line and left to the "3" and then type r0
  17. move the cursor right over the "0" and then type r6
  18. move the cursor right over the "5" and then type r3
  19. move the cursor left one space and then type r1
  20. Type <escape> and then :wq if all went well (If not then type <escape>:q! instead)
  21. The screen should look like this:
  22. type <return>
if anything went wrong then type cp crontab.original crontab to restore the original file.

This will now run the daily maintenance at 1:02 p.m. instead of at 3:15 a.m., the weekly maintenance at 1:04 p.m. instead of at 4:30 a.m., and the monthly maintenance at 1:06 p.m. instead of at 5:30 a.m. For me these are when I am taking lunch - you can adjust the hours and minutes to your own liking - just keep the columns aligned.

In order to give yourself an audio reminder that the maintenance is about to take place you could do the following in the terminal: type setenv EDITOR /usr/bin/vi and then <return> type crontab -e <return>. After the editor has started (it may already have contents in it, but it is more likely to be empty), type i and then:
#minute hour mday month wday command<return>
0 13 * * * /usr/bin/osascript -e 'say "Maintenance will occur during the next fifteen minutes."'<return>

Type <escape> and then :wq if all went well (If not then type <escape>:q! instead)

What did I just do?

The procedure above edited two files that unix uses. Neither of them are required but if they are present then unix will read them and do what they request. The are both called crontab files. The first belongs to the operating system ("root") and can be found at /private/etc and is executed whenever the computer is booted up. The second crontab file belongs to a given user and will be run whenever that user is logged in. These files will operate if the computer is running and is NOT in sleep state. The files execute other applications or programs at specific times. The root crontab file runs three periodic maintenance programs that clean up a lot of temporary trash on the hard drive. They may also execute other tasks. The user can have his/her crontab file execute applications or programs on a regular basis. This is a powerful way to make your computer perform tasks on a regular basis all on it own - geeks love this capability and have found lots of uses for it. If you have understood all of this so far . . . you may be a geek.

Is there an easier way?

If you do not have your computer on at night the default crontab will not execute its maintenance applications at all. You can either run them manually from the terminal by typing the following three commands (each will take two or three minutes to run)
sudo periodic daily
sudo periodic weekly
sudo periodic monthly
If you do not wish to use the terminal, an alternative user friendly way is to run a freeware program called MacJanitor that runs the maintenance programs, or a shareware program called Cocktail that does this and many other useful maintenance tasks - see the Software page for more on these programs.

return

Copyright:

Made on a Mac

©Macintosh Appreciation Group of Island County (MAGIC) 2004
last updated: 22 September 2004