Timed Shutdown or Restart

jturnage
New Contributor III

Hi all!! We are looking for a solution to auto shutdown machines at a certain time each day. The reason for this is because students are caching social websites and games to play during school. These websites are normally blocked. A simple restart has been the solution to keep students from doing this but automation is definitely the way to go rather than a verbal cue from a teacher in each class every morning.

I have tried the Energy saver preferences in the configuration profile but this gives each student the option to cancel the restart. Just needing some solution to send a shell script or something to trigger at a certain time. This would also need to run on checkin if the students machine was sleeping at the time triggered and then opened at a later time. Thanks in advance for any direction you have to offer. Looking forward to your responses.

5 REPLIES 5

mm2270
Legendary Contributor III

I would look at deploying a LaunchDaemon to handle this. There are ways in a script to force a reboot, and not use the reboot from the Apple menu method which pops up the dialog that can be cancelled.
Having this run on a calendar schedule from a LaunchDaemon also removes the need to have it controlled by a Casper policy, meaning it will reboot even if the Mac is not connected to any internet/network connection at all.

jturnage
New Contributor III

Thanks Mm2270, Do you have a link to some good starting places to learn about this. I have never touched LaunchDaemon and want to get it right without messing anything up.

smb_samba
New Contributor III

You could have a policy set to run the sudo jamf reboot command (type in jamf help reboot in terminal to find more information). You could set the policy to run this using client-side limitations and set the time-range you want.

NoahRJ
Contributor II

@jturnage, Apple's official documentation in the developer library has a lot of really good information about daemons and services, especially helpful if you're just getting started. Below is the direct link for scheduling timed jobs with launchd (and cron, although that's been depreciated):

https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Sch...

Look
Valued Contributor III

I have a forced wake on desktop machines that I use for software updates that may help.
Basically there is a policy scoped to machines requiring updates that runs the following.
It wakes the machine at a semi random time between 1am and 2am the following morning.
I then have software update policies set to only run after hours, which for classroom machines includes a forced restart at the end.
Pretty sure you can script a straight shutdown or restart as well using the same pmset.
You might want to be careful of force waking laptops though, just in case they are some where they present a fire risk (ie: in a backpack or something).

#!/bin/bash
TomorrowsDate=`date -v +1d +"%m/%d/%Y"`
RandomMinutes=`date +"%S"`
pmset schedule wakeorpoweron "$TomorrowsDate 01:$RandomMinutes:00"