I want to power off multiple Macs everyday at 23:30 (11:30 pm)?
I have this problem in my office that multiple Macs always run 24/7 and my boss said that I need to make it stop. Now I don't have much experience with Macs, I'm more the Windows type.
I have one Mac who acts as a server and would like to run a script or something like that to orchestrate the power status of several computers if that helps.
How can I shut down all of those 7-8 Macs remotely at 11:30pm?
As patrix has pointed out in a comment, you can set up any Mac to start up or wake up, and sleep or shut down at specific times, via the System Preferences -> Energy Saver -> Schedule... settings.
You could also try using AppleScript, e.g. this code (edit it with Script Editor, then save as an Application):
tell application id "com.apple.systemevents" -- System Events.app
shut down
end tell
And then use OSX's Launch Services to run this script at a given time. To set this up, you could use a free tool such as "Lingon X".
Besides, why shut them down like this? If all you care about is to preserve electrical power, why not instead set up the Macs to go to Sleep after being idle for, say, 30 minutes? That way, they will go to sleep much sooner usually, saving more power. If they do not go to sleep as expected, you can check with the Terminal command pmset -g
what might prevent them from sleeping. Often it's a pending print task (which you may want to delete, then) or mounted server volumes.
You can use pmset
to do this and it will be a "once and done" solution.
Once you issue the pmset
command, it will shutdown/startup/wake on the schedule you set; you won't have to create a script that runs at a predetermined time each time.
pmset
uses this format:
pmset schedule day/date time
Here are a few examples:
pmset repeat sleep MTWRF 23:30:00
puts the Mac to sleep weekdays at 11:30pmpmset repeat poweroff MTWRF 23:30:00
shuts down the Mac weekdays at 11:30pmpmset schedule shutdown "12/31/2016 23:59:00"
shuts down the computer at 11:59pm New Year's Eve.pmset repeat wakeorpoweron MTWRF 06:30:00
wakes the Mac every weekday at 7:00am so that it's ready to go when the employee shows up.
You don't need to use a script to do this, all you need to do is remotely access each one of the Macs (all 7 or 8) of them and issue the command as an admin.
However, if you needed to run a script you could add this command to a simple bash script similar to the following:
#!/bin/bash
# Array of Mac hostnames separated by spaces
my_macs=(mac1 mac2 mac3 mac4)
#Steps through each hostname and issues SSH command to that host
for n in my_macs
do
ssh admin@$n "pmset repeat sleep MTWRF 23:30:00"
done
exit 0
Now, keep in mind that the script is for illustration purposes and technically outside the scope of this answer. I just wanted to illustrate how this could be done.
If you need to manage a bunch of Macs, I recommend using Apple Remote Desktop. It should let you push any number of standard settings to the Macs you need to manage for your job and let you avoid having to write and maintain a script.
On each machine you need to enable Remote Management
in System Preferences.app > Sharing. After that, you can adjust anytime you need to.