Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > How to make Software Update install updates at night?

How to make Software Update install updates at night?
Thread Tools
JazzCatDRP
Mac Enthusiast
Join Date: Sep 2004
Status: Offline
Reply With Quote
Nov 23, 2008, 05:43 PM
 
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.
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 23, 2008, 06:00 PM
 
The only thing I can think of is to put /usr/sbin/softwareupdate -i -a in the root crontab.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 23, 2008, 07:22 PM
 
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...
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 23, 2008, 07:55 PM
 
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.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Cold Warrior
Moderator
Join Date: Jan 2001
Location: Polwaristan
Status: Offline
Reply With Quote
Nov 23, 2008, 08:08 PM
 
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.
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 23, 2008, 08:14 PM
 
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.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 23, 2008, 08:36 PM
 
Originally Posted by Cold Warrior View Post
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
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 23, 2008, 08:42 PM
 
What exactly are the differences between shutdown -r now and reboot?
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 23, 2008, 09:17 PM
 
Originally Posted by besson3c View Post
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 View Post
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...

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 23, 2008, 09:32 PM
 
Originally Posted by CharlesS View Post
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.
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 23, 2008, 09:57 PM
 
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\""

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Nov 24, 2008, 01:40 AM
 
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
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 24, 2008, 03:06 AM
 
If you made it, shouldn't you know what it does when a restart is required?

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 24, 2008, 03:42 AM
 
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'."
     
0157988944
Professional Poster
Join Date: May 2007
Status: Offline
Reply With Quote
Nov 24, 2008, 05:09 PM
 
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.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 24, 2008, 05:36 PM
 
Originally Posted by adamfishercox View Post
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?
     
0157988944
Professional Poster
Join Date: May 2007
Status: Offline
Reply With Quote
Nov 24, 2008, 05:43 PM
 
why would you not just wake the computer and run software update? which would then leave a dialog box saying "Requires a restart"
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 24, 2008, 05:57 PM
 
Originally Posted by adamfishercox View Post
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.
     
0157988944
Professional Poster
Join Date: May 2007
Status: Offline
Reply With Quote
Nov 24, 2008, 05:58 PM
 
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.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Nov 24, 2008, 06:01 PM
 
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.
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 24, 2008, 06:06 PM
 
Originally Posted by adamfishercox View Post
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.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Nov 24, 2008, 06:38 PM
 
Originally Posted by CharlesS View Post
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. )
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Nov 24, 2008, 07:13 PM
 
Originally Posted by wataru View Post
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.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:56 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,