|
|
How to make Software Update install updates at night?
|
|
|
|
Mac Enthusiast
Join Date: Sep 2004
Status:
Offline
|
|
My in-laws just made the switch to Mac, and they're having some problems with their satellite internet service's measly cap. They'd like to have Software Update do it's thing at 3 am (when they have unlimited downloads). Is there any way to schedule this? The best I saw was scheduling how often it checks for updates, but wouldn't let me specify a time.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
The only thing I can think of is to put /usr/sbin/softwareupdate -i -a in the root crontab.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Looking at the manpage, it doesn't look like there is a flag to get softwareupdate to reboot the computer for updates that require a reboot, so I'm not sure how well that would work...
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Yeah, that's a problem. I suppose one could do it in a paranoid way and simply make a shell script that runs SU and then reboots every time, but that is of course a problem because any unsaved work will be lost if you use the reboot tool, and unsaved work will cause the machine not to reboot at all if you use AppleScript to do it nicely. Hmm...
I suppose you could make a script that would attempt to log out any users that are logged in, and if it is successful, then run softwareupdate -i -a and reboot. If it is unsuccessful logging out, it could throw up a "Software Update not run due to unsaved work, but there are updates out and you should run it sometime" dialog or something so that you'd know in the morning. Perhaps in this case it could run softwareupdate -d -a so that the packages would be downloaded and ready to install manually if you wished.
Hmm, actually softwareupdate -l seems to put [restart] after any updates that need a reboot. So you could just run that and search for [restart] to see if you need to reboot or not.
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Jan 2001
Location: Polwaristan
Status:
Offline
|
|
It may be easier to locate the stand-alone download links and use a software program (or can wget be scheduled?) to start the queue at 3 am.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
If you run softwareupdate -d -a, that downloads all the updates to your Downloads folder, I believe, so no need to ferret out the download links and mess with wget.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by Cold Warrior
It may be easier to locate the stand-alone download links and use a software program (or can wget be scheduled?) to start the queue at 3 am.
wget, curl, fetch, and other tools can be put into a cronjob, but you would probably have to build a website screen scraper to pluck out the links from the site, and if the structure of the site is every drastically altered your script would break.
Like Charles has stated, softwareupdate works for downloading and/or installing packages, it's just deciding when to reboot that is problematic.
The way I would do it is this (I haven't tested this, there may be errors in here)
Code:
#!/bin/sh
softwareupdate -l | grep "\[restart\]" > /tmp/packagesrequiringreboot
if [ `cat /tmp/packagesrequiringreboot | wc -l` gt 0 ]
then
rm /tmp/packagesrequiringreboot
softwareupdate -ia && reboot
else
rm /tmp/packagesrequiringreboot
softwareupdate -ia
fi
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
What exactly are the differences between shutdown -r now and reboot?
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally Posted by besson3c
wget, curl, fetch, and other tools can be put into a cronjob, but you would probably have to build a website screen scraper to pluck out the links from the site, and if the structure of the site is every drastically altered your script would break.
Not really... if you use the "strings" tool on /System/Library/PrivateFrameworks/SoftwareUpdate.framework/SoftwareUpdate and grep it for a line starting with http and ending with .sucatalog, you'll get an XML file containing the download links to all the software updates. It's not necessary, though, since softwareupdate -da will do that for us.
Originally Posted by besson3c
What exactly are the differences between shutdown -r now and reboot?
I don't think there is a difference, but the bad thing about both of them is that they will kill all running apps without asking to save changes first, which might be a bit of a dangerous thing to do for your in-laws - they might leave a document open overnight without saving it, and get mad at you when it's hosed the next morning...
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by CharlesS
Not really... if you use the "strings" tool on /System/Library/PrivateFrameworks/SoftwareUpdate.framework/SoftwareUpdate and grep it for a line starting with http and ending with .sucatalog, you'll get an XML file containing the download links to all the software updates. It's not necessary, though, since softwareupdate -da will do that for us.
Cool, didn't know that. In the back of my head I was thinking about the public site that Apple provides for downloading packages, whatever that URL is now.
I don't think there is a difference, but the bad thing about both of them is that they will kill all running apps without asking to save changes first, which might be a bit of a dangerous thing to do for your in-laws - they might leave a document open overnight without saving it, and get mad at you when it's hosed the next morning...
Yeah, so I guess the best solution is to combine my script with some sort of Applescript that is invoked when a reboot is necessary to notify the inlaws.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Something like this should work:
osascript -e "tell application \"System Events\" to display dialog \"Hey, I just installed some software updates that require you to restart the machine, and the machine will probably be in an unstable state if you don't. So, please restart as soon as possible, or else I am not responsible if your computer explodes and fills your smelly in-law face full of shrapnel.\" buttons \"Okay, okay already\""
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
I remember making a quick launchd item that forced software updates to be installed. I put it on my parents' machine because they refuse to install software updates for some reason. I don't know what it does when a restart is required, but it seems to do the job.
There's a nice GUI tool for making launchd items: Lingon
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
If you made it, shouldn't you know what it does when a restart is required?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I suppose he wouldn't if he didn't special-case restarts and didn't have a mandatory-restart update in his queue when he was testing it.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: May 2007
Status:
Offline
|
|
you don't need it to restart at 3 am... SU downloads completely and then requires a restart. All the needs to happen overnight is downloading.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by adamfishercox
you don't need it to restart at 3 am... SU downloads completely and then requires a restart. All the needs to happen overnight is downloading.
And how would the owner of the computer know that an update was installed that requires a reboot if invoked via a cronjob?
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: May 2007
Status:
Offline
|
|
why would you not just wake the computer and run software update? which would then leave a dialog box saying "Requires a restart"
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by adamfishercox
why would you not just wake the computer and run software update? which would then leave a dialog box saying "Requires a restart"
Because the OP wanted the job to run automatically overnight. Software Update already provides notification of when an update is ready to be installed.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: May 2007
Status:
Offline
|
|
run it to download.. then once it is downloaded it will still need an install, or throw up the dialog anyway. I must be missing something here.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Not to speak for the original poster, but I think he wanted to force downloads and installs of updates like Windows can do, and wanted to do these during non-peak times when there are no bandwidth usage limits with their particular internet service.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally Posted by adamfishercox
run it to download.. then once it is downloaded it will still need an install, or throw up the dialog anyway. I must be missing something here.
You are. Try running this command sometime to see what we're working with:
sudo softwareupdate -ia
The command-line tool does not throw up any dialogs. It simply downloads and installs the updates, and afterward you are responsible for rebooting the computer yourself. The GUI tool throws up dialogs, but since it would require an elderly couple to stay up until 3 AM to enter the admin password before it would do anything, it's not a good solution in this particular case.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
Originally Posted by CharlesS
If you made it, shouldn't you know what it does when a restart is required?
It wasn't a script; I just made a launchd item that runs /usr/sbin/softwareupdate -i -a as root (I think). I don't know what happens when an update requires a restart because no such updates were released while I was at my parents' house. I imagine nothing happens. My parents turn the computer off daily so it's not an issue as far as I can tell.
(
Last edited by wataru; Nov 24, 2008 at 08:27 PM.
)
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally Posted by wataru
It wasn't a script; I just made a launchd item that runs /usr/sbin/softwareupdate -i -a as root (I think). I don't know what happens when an update requires a restart because no such updates were released while I was at my parents house. I imagine nothing happens.
What happens is nothing much - the tool just outputs something along the lines of "You've installed something that needs a restart - please do so immediately."
My parents turn the computer off daily so it's not an issue as far as I can tell.
Ah, this isn't a bad idea at all - just set a scheduled shutdown at 5 AM or some other that's well after 3 AM, in the Energy Saver prefs. I assume that Energy Saver does a "safe" shutdown that avoids losing unsaved data. Why didn't I think of that?
Of course, the "please reboot soon" dialog box could work too, but it requires the users to take it seriously.
You could also set a scheduled startup / wake from sleep slightly before 3 AM so the update would still run even if someone had shut down the computer or put it to sleep.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|