Scheduling Software Update

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
Looking for a command line method to modify the appropriate plist file and set the Software Update time. I've scanned the internet to the extent that I can on this slow connection but can't seem to find an elegant way of doing this. There are a few workarounds like - staying up until after 2:30 and manually initiating - or I could reset the system clock and manually update - then adjust the clock. But I'm looking for something better - if it exists.

I've found the com.AppleScheduler.plist and com.SoftwareUpdate.plist - but I don't see the field for this. I'm expecting to see a field that shows the last time I updated - or checked for an update - and I cant find it. Now that I live out in the sticks - I have limited BW and caps on my downloads - so I need to schedule these for off-peak hours. Any thoughts on the best way to do this?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You, my good man, have come to the right place. All you need is cron and softwareupdate (the command line tool for SU).

So, softwareupdate has a few options. You can have it update all updates or only required ones. It's up to you. If you want to install all updates, this is the command you want:
Code:
echo password | sudo -S softwareupdate -ia
If you only want the required ones, use the following:
Code:
echo password | sudo -S softwareupdate -ir
Put the command into a plain text files and make it executable:
Code:
chmod +x /path/to/script.sh
Make sure to replace "password" with your password. Note that the insecurity here is that you're storing your password in plain text in that script. If that's ok, perfect. If not, you can edit your sudoers file to add your user so that you don't have to enter your password by following this. If you make that change, modify the script commands such that they look like the following (which ever one you want):
Code:
sudo softwareupdate -ia
Code:
sudo softwareupdate -ir

So, that's your command. Now, to schedule it, we're going to use cron. Execute the following to edit the crontab (file responsible for scheduled commands):
Code:
crontab -e
Enter the following to schedule the execution of that script (and thus SU) at 2:30AM:
Code:
30 2 * * * /path/to/script
Push escape, enter :wq and finally push enter.

Presto - SU executes at 2:30AM every day. Don't like the time? Change the cron instruction accordingly (the first number is the minute, the second is the hour in 24h format).
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
Hehe - I'm still trying to digest your answer - but of course you I know I'm a Linux/Unix rank amateur. I actually thought about sending you this question - because somehow I knew you'd have the answer. You're pretty smart for an education major :p and nowhere near as dumb as Razor says!

I'm off to give this a try. :) I'll be back soon with everything I screwed up.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Hehe - I'm still trying to digest your answer - but of course you I know I'm a Linux/Unix rank amateur. I actually thought about sending you this question - because somehow I knew you'd have the answer. You're pretty smart for an education major :p and nowhere near as dumb as Razor says!
I have to have a little chat with Razor then. Since I don't know which one, I'll talk to them both, haha.

I'm off to give this a try. :) I'll be back soon with everything I screwed up.
Set the time for something close to now (22:00 or so) and see if it works.
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
I'm already stuck on the "make the script an executable" step. I have a plain text file - called SWUpdateScript - but it doesn't like the next step chmod etc etc - says there's no such file. Now I note that you have a .sh extension - does the file need to have that extension when saved?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,108
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Definitely the other Razor..:)
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
Nevermind - figured out what I was doing wrong there.
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
What do I need to hit before entering the update time and path in crontab? It won't let me enter anything - except I can exit using :wq
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,108
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
You might ave to hit 'i' before entering that info..
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You might ave to hit 'i' before entering that info..
Of course I forget a step. This is what I get for assuming everyone knows how to use vim. :p
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,108
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Of course I forget a step. This is what I get for assuming everyone knows how to use vim. :p

I use it so often, that I assume the same, going in and out of edit mode is normal practice for me..:)
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
So - I'm still not doing something right. Was able to create the crontab file - and put int a time to test - but haven't seen any sign that it's executing - and when I executed it from the command line - it told me the system admin was installing updates.

It has told me I have new mail in /var/mail/Me - which tells me there's probably an error message waiting for me.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Not necessarily - mail is "sent" to you (this is the system mail - it's a Unix thing) upon completion of any cron task.

The joy of doing this in the background is that you won't see anything. The command is being executed behind the scenes. An example from my machine are my backups to Dropbox. When a cron job runs, I have no idea until I see Dropbox syncing my data right on schedule.

The easiest way to find out if this worked is to check the App Store for updates.
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
This works for the App Store as well? When I check SW update - it still shows the same pending - but uninstalled updates as previously. When I ran the command that's in the script manually from the command line - it popped a window up telling me SW was being updated. I haven't seen anything like that - and both the App Store and SW update are still showing the same pending updates.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
No, the softwareupdate tool is only for OS X updates. You noted that you were looking for a scheduled solution for SU, not AS updates. If you want AS updates scheduled as well, I'll have to do some research.

I ran the script here last night and I know it works - it installed some updates and I now get the delightful "No Updates Available" message in the AS.

For this to work, the script needs to be executable. If it's not, cron will try to run it and fail since it has to run stuff that's executable. Now, you seem to have done something interesting here - that softwareupdate tool does not pop any windows up. In fact, that would defeat the purpose of the tool (to run unobtrusively in the background). When you get a chance, try running the command from the command line manually to verify that you've got the syntax right.

Here's what mine Terminal window looks like (yours will show progress for a set of updates if there are some):

Screen Shot 2012-11-14 at 10.04.28 AM.png
 

bobtomay

,
Retired Staff
Joined
Dec 22, 2006
Messages
26,561
Reaction score
677
Points
113
Location
Texas, where else?
Your Mac's Specs
15" MBP '06 2.33 C2D 4GB 10.7; 13" MBA '14 1.8 i7 8GB 10.11; 21" iMac '13 2.9 i5 8GB 10.11; 6S
You, my good man, have come to the right place. All you need is cron and softwareupdate (the command line tool for SU).
...


I got lost right there. What's cron?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,108
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Cron is essentially a scheduler that can run various tasks at a given time. This is usually used to do routine things on the system like log rotation or system updates or whatever.

On Linux machines there are various log files in the /var/log directory that track everything that happens on the system and these files can get very large, so there is a logrotate script that is set to run every day that does what the name implies. It copies the current file to a backup by appending the time to the end. Once there are 5 (or whatever number) backups, the oldest is deleted and so on..

There is a system level crontab (Cron table with tasks) and each user can have their own to do routine stuff just in their home directory or system level stuff..

As Van said, most people use it for backing up data to a different server/computer at night depending on the size of the backup..
 
OP
BrianLachoreVPI

BrianLachoreVPI


Retired Staff
Joined
Feb 24, 2011
Messages
3,733
Reaction score
124
Points
63
Location
Maryland
Your Mac's Specs
March 2011 15" MBP 2.3GHz i7 Quad Core 8GB Ram | Mid 2011 27" iMac 3.4 GHz i7 16 GB RAM 2 TB HDD
Really odd. I just ran the command echo pwd | sudo -S softwareupdate -ia -- as I had yesterday by accident since I didn't properly read the part about putting into a text file first - but this time no pop up window.

I can confirm that the script file has that syntax with no errors - and that it is indeed an executable script since MacOS informed me of that when I just double clicked on it to examine contents.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Is your cron syntax correct? If the script works fine, the cron entry may be malformed.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top