Scott's answer is essentially correct, but a better method would be the following command (see the softwareupdate
man page for full details):
/usr/sbin/softwareupdate --install --all --schedule off && /sbin/reboot
The addition of --schedule off
will prevent the machine from checking & notifying the user of new updates the rest of the time. && /sbin/reboot
will restart the machine if softwareupdate
finished without error.
Also, I'd highly suggest that this be run from launchd
for the sole reason that if the machine is asleep at the time it's supposed to fire, it'll be run as soon as the machine is woken up. It still won't fire off the job if the machine was off, but it's at least a little more intelligent than cron
.
An example launchd
plist file is as follows (see the launchd.plist
man page for further details) and would need to be saved in /Library/LaunchDaemons/
as something like tld.domain.asu_reboot.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>tld.domain.softwareupdate</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/asu_reboot</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
And the command would be put into a bash
script in /usr/local/sbin/asu_reboot
(Apple Software Update Reboot) called by the above launchd
plist, like so:
#!/bin/bash
/usr/sbin/softwareupdate --install --all --schedule off && /sbin/reboot
With those two items in place (the bash
script and the launchd
plist), you would run the following command to load the job (or reboot the machine and it'd load automatically):
sudo launchctl load -w /Library/LaunchDaemons/tld.domain.asu_reboot.plist