shutdown multiple Macs after a runtime of 24 hours? Can I shutdown multiple Macs in my office (9-10 Macs) in my office after checking their runtime? I have one Mac, which acts as a Server (with the OS Server application). SSH is also enabled on every Mac, so logging on remotely is not a problem. I want to write a script that checks: 

if the runtime &gt;=24h then shutdown mac


Now I don't know anything about scripting on a Mac but I've done this before with powershell and windows machines. 

Curently I have this script:

#!/bin/bash
BOOT_TIME=$(sysctl -n kern.boottime | sed -e 's/.* sec = \([0-9]*\).*/\1/')
CURR_TIME=$(date +%s)
MAX_UPDAYS=1 #Days

DAYS_UP=$(( ( $CURR_TIME - $BOOT_TIME) / 86400 ))
    if [ $DAYS_UP -ge ${MAX_UPDAYS} ];then
        echo Mac is going to shutdown 
        shutdown -h now
    else
        echo No shutdown needed
fi


but don't know how to run it on the remote Macintoshs
You can do this with a simple bash script, the uptime command and launchd.  If you execute the command by itself, it will tell you how long the machine has been up:

$ uptime
6:08  up 20 days, 21:09, 4 users, load averages: 1.09 1.29 1.36


So, the number that we are interested is the "20" which we will evaluate against our condition of "1 day"

#!/bin/bash

#Maximum number of days to be up
max=1

#Get the uptime days and assign it to a variable
uptime_days=`uptime | cut -d " " -f 5`

if [ $uptime_days -ge $max ]
  then 
  shutdown -h now
fi

exit 0


Make sure you set the script as executable or it won't run:

chmod +x shutdown24.sh

Now, here's the most important part.  When do you want to evaluate this?  Technically, your could have this script run every hour (or even ever minute) to evaluate if the computer has been up for 24 hours.  

This is not recommended because if for some reason the computer was turned on at 10:00am (because the person was late, for example) you don't want it shutting down at 10:00am the next morning when they are in the middle of their work.

So, I'm going to assume you want it run at midnight so you don't inadvertently shutdown the machine while people are working.  What you need is to utilize lauchd and create a .plist that defines the job (similar to Task Scheduler) in Windows.

Let's assume that we called the bash script shutdown24.sh so we will call our .plsit com.user.shutdown24.plist

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.user.shutdown24&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/Users/USERNAME/Path_to_Scripts/shutdown24.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;array&gt;
    &lt;dict&gt;
        &lt;key&gt;Hour&lt;/key&gt;
        &lt;integer&gt;00&lt;/integer&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;00&lt;/integer&gt;
    &lt;/dict&gt;

&lt;/dict&gt;
&lt;/plist&gt;


Copy this file to /Library/LaunchDaemons and then load it to launchd:

sudo launchctl load com.user.shutdown24.plist

The job will be run as root and at 12:00am every morning, it will check if the system uptime and will shutdown if it's greater than 24 hours.