how do i change the time maintenance scripts run?

talin

Registered
i want to change what time the daily/weekly/monthly maintenance scripts run. basically, i want them to run when my computer is more likely to be awake. is this possible?

i have onyx and have been manually running the maintenance scripts, but if possible, i would prefer not to have to mess around with onyx every day.

any help would be much appreciated!
_______________
12' powerbook G4
os x v10.4.5
 
thanks for the very fast response! i have another question tho:)

downloaded anacron then in the log file i got error message so i did what the directions said to do:
__________________________________
Messages reading "cp: error processing extended attributes: Operation not permitted" are from an error in Apple's periodic script. To get rid of the messages, carefully edit /usr/sbin/periodic to substitute > $tmp_output in place of cp /dev/null $tmp_output

__________________________________

the problem is, it won't let me save. gives the message: Couldn’t save document as “periodic” in folder “sbin”.

hmmm...what should i do now?
 
Or, you can ...

01. Set up a 'root' account.
02. Log in as 'root'. If you do not have 'fast user switching' enabled - you will have to 'log out' of the existing account.
03. Seiect 'Finder's 'Go, Go to Folder...' menu item ('Command <shift> G'), and in the 'Go to Folder' drop down sheet or separate 'Go to Folder' window, that appears, enter ...

/private/etc/

... and click on the 'Go' button.

If a file' crontab' exists ...
04. Drag 'crontab' onto 'TextEdit's 'Dock' based icon.
05. Add text such as ...

# Run daily/weekly/monthly jobs.
01 3 * * * root periodic daily
02 3 * * * root periodic monthly
03 3 * * * root periodic weekly

... and select 'TextEdit's 'File, Save' menu item.

If a file 'crontab' does not exist ...
04. Open (run, launch) 'TextEdit', and select its 'Format, Make Plain Text' menu item.
05. Add text such as ...

# /etc/crontab
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
# Run daily/weekly/monthly jobs.
01 3 * * * root periodic daily
02 3 * * * root periodic monthly
03 3 * * * root periodic weekly

... and select 'TextEdit's 'File, Save' menu item.

Note: as per '01 3 * * * root periodic daily' you enter the text as such ...

01<tab>3<tab>*<tab>*<tab>*<tab>root<tab>periodic daily

This also applies for '02 3 * * * root periodic monthly' and '03 3 * * * root periodic weekly'.
Also, I have 'periodic daily' executed at 3.01 (AM), 'periodic monthly' executed at 3.02 (AM), and 'periodic weekly' executed at 3.03 (AM). Change the values to what times you want the 'periodic's to execute.

If a file' crontab' exists ...
06. Save the changes - 'File, Save' menu item.

If a file 'crontab' does not exist ...
06. Save the changes - 'File, Save' menu item, and enter 'crontab' as the file's name, making sure you save the file the 'Desktop', and then dragging the 'Desktop' based 'crontab' file onto the opened '/private/etc/' folder's window.

07. Quit 'TextEdit'.
08. Log out as 'root' via the 'Apple, Log out System Administrator' menu item.
09. Log in to an existing account, to again use the Macintosh.

---

Now, let the Mac do what it is supposed to do - all without the need of any additional applications, error messages, file changes, etc.

[
Added 25 Feb. 2006, at 14.25.

The above instructions work, as is, without any additional steps needed, for 'Panther' (MacOS X 10.3.x); and, possibly 'Jaguar' (MacOS X 10.2.x).

---

For the above to work with 'Tiger' (MacOS X 10.4.x), and not to duplicate the 'periodic' executions - once by 'crontab' and once by 'Tiger's 'launchd' daemon / agent manager ...

... while logged in as 'root', go to '/Library/' and create a 'LaunchDaemons_disabled' folder. Then drag the three (3) files: 'com.apple.periodic-weekly.plist', 'com.apple.periodic-monthly.plist', and 'com.apple.periodic-daily.plist' from the '/Library/LaunchDaemons/' folder onto the '/Library/LaunchDaemons_disabled/' folder.

Or, if you prefer to use 'Tiger's 'launchd' services, instead of 'crontab' to manage your 'periodic's; but, at times (hours, minutes, which day, how often, etc) you want (other than what is currently entered), then ignore the above steps 03. through 09.; and instead, do the following.

03. Open the '/Library/LaunchDaemons/' folder.
04. Select and drag the three (3) files: 'com.apple.periodic-weekly.plist', 'com.apple.periodic-monthly.plist', and 'com.apple.periodic-daily.plist' onto 'TextEdit's 'Dock' based icon.
05. In 'com.apple.periodic-daily.plist's opened window scroll down to ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>15</integer>
</dict>

... and edit the <interger> values. The first value being - the Hour, and the second value - the Minute.

As in my earlier example, this piece of code would be edited as ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>1</integer>
</dict>

07. Save any changes.
08. In 'com.apple.periodic-weekly.plist's opened window scroll down to ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>6</integer>
</dict>

As in my earlier example, this piece of code would be edited as ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>3</integer>
</dict>

... and edit the <interger> values. The first value being - the Hour, the second value - the Minute, and the third value - the Day in the week.
09. Save any changes.
10. In 'com.apple.periodic-monthly.plist's opened window scroll down to ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>5</integer>
<key>Minute</key>
<integer>30</integer>
<key>Day</key>
<integer>1</integer>
</dict>

As in my earlier example, this piece of code would be edited as ...

<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>2</integer>
</dict>

... and edit the <interger> values. The first value being - the Hour, the second value - the Minute, and the third value - the day of the month.
11. Save any changes.
12. Quit 'TextEdit'.
13. Log out as 'root' via the 'Apple, Log out System Administrator' menu item.
14. Log in to an existing account, to again use the Macintosh.
]
 
talin said:
i want to change what time the daily/weekly/monthly maintenance scripts run. basically, i want them to run when my computer is more likely to be awake. is this possible?
If your computer is not awake when the daily/weekly/monthly cron scripts are supposed to run, then they will not run at that precise time (obviously). However, there is no need to force them to run, as they'll simply run when your computer does awaken.

If you check your Console application, you can see that these scripts run when they're supposed to automatically, without you having to run them manually. For example, my computer sleeps all night, so the scripts don't get run at 3am (or whenever they're set to run). Checking Console, under /var/logs, under "daily.out" (and likewise, "weekly.out" and "monthly.out"),I can see that the "daily" script ran at 9:33am this morning -- precisely the time I woke my computer up this morning. Looking backward in the log, I can see that the daily script ran every day at some point soon after I awoke the computer that day.

There is no need to run these scripts manually, because then you'd be running them twice: once automatically when the system awakes, then again when you force it to run.
 
talin said:
the problem is, it won't let me save. gives the message: Couldn’t save document as “periodic” in folder “sbin”.

hmmm...what should i do now?

My method was to edit the file as "root" in Terminal using sudo.

open Terminal
"sudo pico /usr/sbin/periodic" without the quotes
find and edit the text
ctrl+O
enter
ctrl+X

jb
 
Also, if one is curious, you can determine "exactly when your maintenance scripts were last run...

You can execute a Terminal command to quickly check the date and time stamps of the log files associated with each maintenance script. This indicates when the scripts' own logs were last updated, and hence when the scripts were last executed by the following...

Launch Terminal, in the Macintosh HD > Applications > Utilities folder.
At the Terminal prompt, type the following, exactly as written:
ls -al /var/log/*.out
Press Return.
You will see output similar to the following:

-rw-r--r-- 1 root wheel 467984 8 May 10:40 /var/log/daily.out
-rw-r--r-- 1 root wheel 1258 8 May 10:43 /var/log/monthly.out
-rw-r--r-- 1 root wheel 198378 8 May 10:43 /var/log/weekly.out
In this example, the scripts last ran on 8 May of the current year, between 10:40 and 10:43 local time. The date and time stamps in the example are the result of running the scripts manually using Terminal. If the scripts were run automatically on their default schedule, their date stamps would vary and their time stamps would indicate executions between 03:15 and 05:30 hours.

jb
 
jbarley said:
If the scripts were run automatically on their default schedule, their date stamps would vary and their time stamps would indicate executions between 03:15 and 05:30 hours.
The times of execution could be any time, depending on when the computer was first awakened after the script was supposed to run.

Here's mine from today:

-rw-r--r-- 1 root wheel 394469 Feb 25 09:34 /var/log/daily.out
-rw-r--r-- 1 root wheel 1579 Feb 1 12:52 /var/log/monthly.out
-rw-r--r-- 1 root wheel 9415 Feb 25 09:41 /var/log/weekly.out

You can see the times were around 9:30 this morning (right around the time I awoke the computer), and those scripts were run automatically without the need for me to force them to run with 3rd-party software or via a command-line command.

I'm stickin' to my guns and saying that 3rd-party software to run the daily/weekly/monthly cron scripts is useless, since they get run automatically the first chance the system has to run them. Running them twice (once automatically by the system, once again by the user forcing the running of them) is not beneficial at all. Running them manually is also pointless.

If the scripts are not running by themselves without user interaction, then that would indicate a deeper problem. In this case, using 3rd-party software or running the scripts manually is simply a band-aid, and a better course of action would be to hunt down the problem that is preventing them from running automatically.
 
I'm stickin' to my guns and saying that 3rd-party software to run the daily/weekly/monthly cron scripts is useless, since they get run automatically the first chance the system has to run them.

This is correct.
 
In fact, launchd seems to be relatively broken.

(1) There is (or at least was) a bug in launchd such that periodic tasks are run only once per boot, no matter how long the computer is up. This may have been fixed, I don't know, as I ususally shut my computer off every night. Anyway, here is one link that refers to this bug http://aplawrence.com/foo-mac/periodic-tasks.html

(2) While periodic tasks that are missed because the computer is asleep are correctly picked up when it wakes up, periodic tasks that are missed because the computer is shut down altogether are never picked up.

For example, I have used my computer on significantly more than three days in the month of February, and yet there are only three entries for that month in /var/log/daily.out. Furthermore, I bought the computer in January, and the weekly and monthly jobs have not run once - there is only a /var/log/daily.out

Code:
0 14:13 mark@Trilby:log $ ls -l *.out
-rw-r--r--   1 root  wheel  4651 Feb 12 17:10 daily.out
0 14:13 mark@Trilby:log $ grep Feb /var/log/daily.out
Sun Feb  5 06:55:08 MST 2006
Wed Feb  8 23:48:03 MST 2006
Sun Feb 12 17:10:01 MST 2006
0 14:13 mark@Trilby:log $

I usually shut my computer off overnight, so those entries probably correspond the three times that it has been left on overnight since I got it.

So yes, unless you can remember to leave your computer on overnight every Saturday night and on the last day of every month (at which point you might as well just run the jobs manually before you shut the computer off), you will need anacron to run them, until launchd works correctly.

Interestingly, the launchd man page doesn't even have a BUGS section.
 
'... launchd seems to be relatively broken.' - which (without going into specific details) is why I still prefer 'crontab'. It just works.
 
scruffy said:
In fact, launchd seems to be relatively broken.
What version of Mac OS X are you running?

I remember another thread with a similar discussion on cron tasks getting run/not getting run. It seemed that people who were running Mac OS X 10.4 Tiger were having the tasks run automatically, while the people running prior versions of Mac OS X didn't have their tasks run automatically.
 
Sorry to butt in on this thread, but it is something I have been trying to sort out as well.
The computer is always switched off between 3am and 5am (except on the rare occassions I am still up) so the scripts will not run at the scheduled time. I have just checked the daily log as described in one of the posts above and the last time the daily script was run was three weeks ago, when I was obviously still up and the computer was awake.
Is the maintenence supposed to take place wirhout the addition of the Anacron program or with it.
I do not want to be messing around with changing code as I will almost certainly mess something up. But obviously these maintainence tasks need to be completed.

Thanks
 
The tasks _should_ run on their own without any extra software, but launchd is broken.

If you want the tasks to be automatically run you'd want to
- install anacron
- make sure anacron gets run (I believe the usual way is to have cron run it every 10 minutes or so)
- add the maintenance scripts to anacron's schedule
- disable the launchd items for the maintenance scripts, to avoid them occasionally being run twice.

And there's always the possibility that Apple will change the launchd items with some future update, and clobber your changes...

For now, perhaps the easiest thing would be to run the scripts manually, and hope Apple gets launchd working properly one of these days...
 
ElDiabloConCaca said:
What version of Mac OS X are you running?

I remember another thread with a similar discussion on cron tasks getting run/not getting run. It seemed that people who were running Mac OS X 10.4 Tiger were having the tasks run automatically, while the people running prior versions of Mac OS X didn't have their tasks run automatically.

I'm running 10.4.5 on an Intel iMac.
 
ElDiabloConCaca said:
If the scripts are not running by themselves without user interaction, then that would indicate a deeper problem. In this case, using 3rd-party software or running the scripts manually is simply a band-aid, and a better course of action would be to hunt down the problem that is preventing them from running automatically.

i have a 12"powerbook G4, os x 10.4.5, purchased 12/31/05 and i put it to sleep every night til about 8am each morning. it is my understanding from this thread and from other sources that with os x 10.4 If your Mac is asleep when the scripts are programmed to run, they will run automatically when you next wake the computer. This is a change from Mac OS X 10.3.

on tuesday, to troubleshoot a different issue, the apple products specialists had me do an erase and install. i did all the updates on tuesday also and today i checked to see if the daily maintenance scripts had run(in terminal, ls -al /var/log/*.out) and it displayed "this log does not exist" so then i checked in onyx and it gave the same message. i then had onxy force the daily maintenance script and sure enough, the log (in both terminal and onyx)shows that the script ran.

so, how do i determine what the problem is and why my system is not running the scripts automatically?

thanks for any help!

oops - forgot to mention that i used the disk utility from the CD to repair disk after i forced the daily script to run - no errors showed up.
 
Below is a segment taken right from OS X "Help", using "periodic" as a search word.
--------------------------------------------------------------------
Quote...
Mac OS X performs background maintenance tasks at certain times if the computer is not in sleep mode. If your computer is shut down or in sleep at the designated times, the maintenance does not occur. In that case, you may want or need to run these manually.
End Quote.
-----------------------------------------------------
Notice that Apple themselves state that the maintenance tasks will NOT run if your computer is in Sleep mode.
This supports what I've always understood and is more then likely the main reason for the various software utilitys produced to address this issue.
I never could believe that a bunch of software engineers would waste their time writing code to solve a problem that did'nt exist.

jb.
 
thanks jb - i did a search of the apple forums where they were saying that scripts run automaticly when you wake the computer if you have 10.4. guess they were wrong:)

i really appreciate everyone's help! i'm such a newbie - all this is a bit confusing for me:)
 
Back
Top