Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Schedule OS X software updates via script System 10.5
This is something I came up with because of a support issue. I've now finally gotten my act together in sharing this with the world at large, inspired by Chris Breen's Scheduling OS X Software Update article at Macworld.com. Now, I'm the resident Mac Guru in the family, and for some associates. One of my female associates has a daughter who has borrowed my old decommissioned second-generation 800MHz 15" PowerPC iMac (you know -- the 'Luxo' model!). She is very happy with it, but I have some support issues as:
  1. Their ISP blocks every outside access, including ssh and vnc
  2. The computer is so old that screen sharing through iChat doesn't work -- that requires at least 64MB on the graphics board, and this model iMac has only 32MB.
Updating Mac OS X Leopard remotely is thus somewhat problematic, so I came up with the idea of automating the Software Update by installing a LaunchDaemon and an associated script. Now, I just have to tell her not to turn the computer off when she goes to bed in the evening, and my script does what's needed.

This is the LaunchDaemon plist file; just save it as info.mathiesen.softwareupdate.plist in /Library/LaunchDaemons. You can, of course, adjust the schedule according to your own wishes.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>info.mathiesen.softwareupdate</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/sbin/softwareupdate</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Minute</key>
        <integer>0</integer>
        <key>Hour</key>
        <integer>2</integer>
    </dict>
</dict>
</plist>
Here is the script that does the dirty work. Put it in /usr/local/sbin, or somewhere else on your path. If you store it elsewhere, change the path in the above plist file to point to the new location. Remember to chmod +x the script file, so it can run.
#!/bin/bash

rm /Library/Caches/*
/usr/sbin/softwareupdate --install --all && reboot
Some explanation might be in order. The reason for the rm /Library/Caches/* is that on all of my PopwerPC computers (I've got three including the iMac), the sound goes completely haywire when iTunes has been updated if those caches haven't been deleted. Clearing the caches completely resolves the sound problem.

Some might ask "Why not just put all of the Software Updates in the plist and do away with the bash script?" There are two reasons for that:
  1. softwareupdate executed in a script or in the Terminal isn't able to reboot the computer by itself like the GUI version is
  2. I need to clear the caches
[robg adds: I haven't tested this one. An alternative solution is presented in this hint.]
    •    
  • Currently 2.11 / 5
  You rated: 1 / 5 (9 votes cast)
 
[15,899 views]  

10.5: Schedule OS X software updates via script | 8 comments | Create New Account
Click here to return to the '10.5: Schedule OS X software updates via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Schedule OS X software updates via script
Authored by: Dr. T on Apr 09, '09 09:51:16AM

Why is this hint necessary? Just have her launch System Preferences, click on Software Update, check the "Check for updates" box, and choose daily, weekly, or monthly. I did that for my daughter before she went to college with her old iMac.

Also, it really isn't a crisis to go without updates for a while. There is a subset of computer users that is overly compulsive about installing every update on the day of release. Let others test for incompatibilities for a week or two and save yourself lots of troubleshooting time.



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: BjarneDM on Apr 10, '09 07:14:06AM

because

  1. she is running as a normal user. Normal users don't see notices from Software Udate
  2. there's the additional requirement to delete the cache files on the computer. Software Update can't handle that, and she isn't computer savy enough to understand and handle the issue. If I just let Software Update handle it she'll have no sound afterwards!

As to the compulsiveness issue she is was two 10.5 point updates behind before I got hold of the computer.



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: lazyman on Apr 09, '09 12:15:43PM

Really? If you're really that concerned about software updates and who ever not running them setup an @weekly cron job. as ron popeil put it: set it and forget it.

Or you could just run ssh on a non-standard port like any sane person would do.



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: BjarneDM on Apr 10, '09 07:30:21AM
Really? If you're really that concerned about software updates and who ever not running them setup an @weekly cron job. as ron popeil put it: set it and forget it.

Well, launchd is for most scheduling issues an Apple recommended replacement for cron as well as most other scheduling services like inetd, xinetd and /etc/rc. With 10.5 Apple migrated all of their cron jobs to launchd. So, I've actually done as you recommend. And with the cache issue, running Software Update straight isn't an option - I'll still need to do it by way of my bash script.

Or you could just run ssh on a non-standard port like any sane person would do.

Any 'sane' person would understand that that's not possible as all outside access to any process no matter what port it's running under is complely blocked at the ISP level. I can't even ping the computer in question!



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: mzs on Apr 13, '09 11:59:08AM

About the ports. My dad would call a lot needing help with an XP computer at his house, so I tried to setup vnc so I could control his screen. I do not think it was the ISP, but rather the wireless router from the ISP that prevented incoming connections, which is actually a good thing in regards to a not well patched-up XP box.

What I did is I installed putty (an ssh client for windows) in addition to TightVNC (or maybe it was ultravnc, can't remember anymore) on his machine. Then I wrote a .bat file that would ssh into my machine at home forwarding port 5900 on his machine to 5910 on mine. Since it was an outgoing connection it worked. Then I would fire-up the vncviewer on the eMac with localhost:5910 and be able to see and control his screen on the XP box.

Then I had an account on my eMac for him that I would uncomment from the sshd_config file when he would call needing help. With this scheme he actually learned how to fix the problems himself very quickly and he has not called in years. It was a lot like a classroom working together on the same machine. We could both type and move the mouse and see what was going on while talking on the phone.

So the key thing was the whole make him do the connection out instead of me in. It was also nice since no one could control his screen without him knowing (the vnc server windows service was configured to only bind to localhost).



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: timkingman on Apr 14, '09 03:51:19PM

I haven't seen the "sound completely haywire" on a G4 eMac running 10.5, so I'd be inclined to think there's some other issue going on there.

Also, an 800MHz iMac doesn't meet the requirements for 10.5, so blaming the video card for iChat screen sharing seems like a stretch.



[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: BjarneDM on Apr 15, '09 07:02:37AM
I haven't seen the "sound completely haywire" on a G4 eMac running 10.5, so I'd be inclined to think there's some other issue going on there.
My three PPC computers are:
  • TiBook 1 GHz
  • TiBook 800 Mhz
  • iMac 15" 800 MHz
They all have the 'delete cache problem'. That you don't see it on your single computer - which is an entirely another model - doesn't mean that the issue isn't there. If you had a model like one of mine without the issue, we could talk business.
Also, an 800MHz iMac doesn't meet the requirements for 10.5, so blaming the video card for iChat screen sharing seems like a stretch.
I'm not putting any blame on the videocard. I'm just stating a fact. You have no grounds for stating that I'm blaming the video card.

[ Reply to This | # ]
10.5: Schedule OS X software updates via script
Authored by: atonaldenim on Jun 25, '09 12:55:58PM

The premise of this article is correct. Scheduling Software Updates via launchd is the ideal method in Leopard. It will run as root, without any user intervention, regardless of whether any user is logged in, at a reliable interval that is easily controlled.

In our small office, our DSL line gets choked up whenever any of the computers decides to automatically start downloading updates. We've made sure to uncheck "Download important updates automatically" in the SU preferences on all machines. (Unfortunately this preference seems to be sometimes forgotten after OS X updates.)

We've had success so far just invoking the softwareupdate command directly from the plist file, rather than creating a separate shell script. Here is our example script to install all available updates every day at 3 am, to be placed in /Library/LaunchDaemons (so it will run as root):


<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
    <dict>
    <key>Enabled</key>
    <true/>
    <key>Label</key>
    <string>org.macosxhints.SoftwareUpdate</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/softwareupdate</string>
        <string>--install</string>
        <string>--all</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>3</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>

The trick is making sure that the computer is turned on at the scheduled time - I don't believe launchd is capable on its own of starting up the computer to run a scheduled task. You can use System Preferences > Energy Saver > Schedule... to make the computer wake or start up just before the Software Update script is set to run, in this case say 2:55 am.

The original poster indicated that the computer may not be able to automatically restart itself this way, but you could use the Energy Saver scheduler to force a shutdown at a reasonable interval afterward, say 4:00am in this example, depending on the speed of the internet connection.

I only wish Apple would provide an interface to schedule Software Updates, as Microsoft has done for ages! In a network of several Macs and only a modest DSL connection, setting Software Update to download only in off-hours is critical.

(Note: the free program Lingon is very handy for creating launchd plists in the right place with the right permissions. Highly recommended.)



[ Reply to This | # ]