Need script to handle interrupted shutdown

Hi, all,

I looked to see if this issue has been posted, but I couldn’t find it.

My iMac is set to shut down at a certain time every day but the shutdown is often interrupted by the message “There is a user sharing this computer. If you shut down they will be disconnected”.

I don’t care if any connected computers are disconnected, so can we write a script that runs in the background (or starts just before my shutdown time) that will answer the Shutdown dialog, thereby allowing the Shutdown to continue ?

If disconnecting the connected computers is easier to script, that would be ok, too.

Thanks for your help,

Scott

Hello.

This is a shot in the dark but the manual states that shutdown -k kicks everybody out, except for the local accounts, so maybe you could try to incorporate the line below before you execute your “real shut donw sequence?”

do shell script "shutdown -k"

Enter man -s8 shutdown in a terminal window to read more . :slight_smile:

Thanks, I’ll look into this… But question… to clarify “the local accounts” - would that include any other computer connected to my iMac on the same network? Because there are no other computers connecting to the iMac except my other computers on the same network.

Scott

Hi McUsr,

When I do this:

do shell script "shutdown -k"

→ error “shutdown: NOT super-user” number 1

Hello.

By local accounts I mean accounts local on your machine.

And please do try

do shell script "sudo -k " with administrator privileges

Thanks for telling me kel! :slight_smile:

If this turns out to be a hindrance for the poster, but the sudo -k solution seem to be the right one, I’ll make something that lets it pass through, by creating a executable with root rights (setuid).

Hello.

The correct commanline for making shutdown -k work is

shutdown -k now

That has to be executed from a do shell script with administrator privileges, so you can’t bypass the entrance of a password really.

It beats me, that you could install it as a launch agent, running as root, to avoid the password. See man launchctl.

Hello.

I have made a launchd plist for you, but you’ll have to read up on launchctl by yourself. The launchd.plist, with the conformant name you choose, should be saved in /Library/LaunchAgents.

The format of the calendar interval, which is quite flexible, is specified in either man cron, or man crontab.

[code]<?xml version="1.0" encoding="UTF-8"?>

Program /sbin/shutdown ProgramArguments -k now RunAtLoad
<key>StartCalendarInterval</key>
<dict>
	<key>Minute</key>
	<integer>0</integer>
	<key>Hour</key>
	<integer>14</integer>
	<key>Day</key>
	<integer>*</integer>
	<key>Weekday</key>
	<integer>*</integer>
	<key>Month</key>
	<integer>*</integer>
</dict>
[/code] You'll probably also have to make root the owner of the plist file. And I haven't tried this, I leave it up to you to get it working, for instance, maybe the integers that holds asterisks, should be changed to for all what I know.

Edit

It does strike me, that if cron is accessible, and has the property still, that it doesn’t execute missed jobs, due to system sleep, then cron is better suited for tasks such as this.