Home AMX User Forum NetLinx Studio

Remote Shutdown of MacOS

Does anyone have good suggestions for doing remote shutdown of Mac CPU's? I do this all the time with Windows-based machines (using i!-ConnectLinx), but I haven't found a thread about doing this with a Mac-OS CPU. (And for all you Bootcamp/Parallels/etc folks: sorry, this needs to be MacOS...)

I'm open to any suggestions! Thanks, all!

Comments

  • Jorde_VJorde_V Posts: 393
    BurbankAV wrote: »
    Does anyone have good suggestions for doing remote shutdown of Mac CPU's? I do this all the time with Windows-based machines (using i!-ConnectLinx), but I haven't found a thread about doing this with a Mac-OS CPU. (And for all you Bootcamp/Parallels/etc folks: sorry, this needs to be MacOS...)

    I'm open to any suggestions! Thanks, all!

    Manually or automated?
  • AvargasAvargas Posts: 57
    you can do it sending an email from the controller:

    http://www.youtube.com/watch?v=Eupb9vbvQPQ&feature=related

    A bit complicated but I can't find anything better.
  • pdavis41pdavis41 Posts: 16
    I wrote a simple shell script that opens a port on the mac and waits for a string. It works great however since it opens a ip port it has to have root permissions. My stumbling block right now is to get it to run on startup.
  • Thanks for the ideas --

    Jorde_V --> I'm not sure what you mean: I just need an AMX controller to be able to shutdown a Mac Mini. Whether it's at a scheduled time, or on a button push doesn't seem (to me) to be an issue. Is there an element to this that I'm missing that would make this distinction important?

    Avargas --> Thanks for the good idea. Unfortunately, I'm on a (very) closed system, so email is out of the question, but the idea of using Applescript is a good one. Is there a way to remotely trigger an Applescript? I'll poke around on some of the Mac guru forums, but if anyone knows a good way, I'm all ears!

    pdavis41 --> This sounds cool and very useful. Could this be used to trigger an Applescript (as above)? That opens up a world of possibilities. (Would you be willing to share your script with the forum?)


    Thanks, everyone! I'm open to all ideas, and I'll let you know what I find!
  • pdavis41pdavis41 Posts: 16
    The script is as follows:

    #!/bin/bash

    listenPort=9
    pckt_shutdown="shutdown"

    echo "Started"

    while `true`
    do
    pckt_data=`nc -l ${listenPort}`
    if $? != 0
    then
    echo "nc returned error."
    exit 1
    fi

    if "$pckt_data" == "$pckt_shutdown"
    then
    echo "Matched! Received shutdown packet, now shutting down..."
    shutdown -h -u now
    exit 0
    fi
    done

    save it as a shell script and run it from a command line. You have to run it as sudo <script_name> though so it has root privileges. I'm still trying to figure out how to get it to run at startup though.
  • AMXJeffAMXJeff Posts: 450
    Remote Shutdown of Mac

    Well... this is a lot easier than all the above... This is basically a unix machine.

    Make sure the telnet daemon is enabled. Which you can do in a terminal window...
    jetson:~ elroy$ sudo launchctl load -w /System/Library/LaunchDaemons/telnet.plist
    

    and... open a TCPIP connection to Port 23 on the mac machine and send the follow commands....

    // raw data
    login: elroy
    Password:
    Last login: Thu Aug 25 16:13:12 on ttys000
    jetson:~ elroy$ su
    Password:
    sh-3.2# shutdown -r now
    

    //netlinx code
    DATA_EVENT[dvShutdownSocket]
    {
    	ONLINE:
    	{
    		STAGE = 1;
    	}
    	STRING:
    	{
    		SELECT
    		{
    			ACTIVE (FIND_STRING(DATA.TEXT,'login:',1) > 0):
    			{
    				STAGE = 2;
    				SEND_STRING dvShutdownSocket,"'elroy',13,10"
    			}
    			ACTIVE (FIND_STRING(DATA.TEXT,'Password:',1) > 0 && STAGE == 2):
    			{
    					STAGE = 3;
    					SEND_STRING dvShutdownSocket,"'elroysecret',13,10"
    			}
    			ACTIVE (FIND_STRING(DATA.TEXT,'$',1) > 0):
    			{
    					STAGE = 4;
    					SEND_STRING dvShutdownSocket,"'su',13,10"
    			}
    			ACTIVE (FIND_STRING(DATA.TEXT,'Password:',1) > 0 && STAGE == 4):
    			{
    					STAGE = 5;
    					SEND_STRING dvShutdownSocket,"'rootsecret',13,10"
    			}
    			ACTIVE (FIND_STRING(DATA.TEXT,'#',1) > 0):
    			{
    					STAGE = 6;
    					SEND_STRING dvShutdownSocket,"'shutdown -r now',13,10"
    			}
    		}
    	}
    }
    
  • Jorde_VJorde_V Posts: 393
    BurbankAV wrote: »
    Thanks for the ideas --

    Jorde_V --> I'm not sure what you mean: I just need an AMX controller to be able to shutdown a Mac Mini. Whether it's at a scheduled time, or on a button push doesn't seem (to me) to be an issue. Is there an element to this that I'm missing that would make this distinction important?

    Avargas --> Thanks for the good idea. Unfortunately, I'm on a (very) closed system, so email is out of the question, but the idea of using Applescript is a good one. Is there a way to remotely trigger an Applescript? I'll poke around on some of the Mac guru forums, but if anyone knows a good way, I'm all ears!

    pdavis41 --> This sounds cool and very useful. Could this be used to trigger an Applescript (as above)? That opens up a world of possibilities. (Would you be willing to share your script with the forum?)


    Thanks, everyone! I'm open to all ideas, and I'll let you know what I find!

    Was going to suggest you don't need to do it remotely if you want to schedule it.

    Remotely you can use the 'shutdown' command, and you can actually let it boot up again using that command as well. (With the -R command) You can ssh/telnet in to the machine to do it. Jeff's solution basically. (A google on 'remote shutdown mac' would've done the trick)
  • Well we came across something huge (at least on a laptop as that was the mac we had on hand to test with).

    If you send a shutdown command to a mac. it will NOT wake up with WoL. It will only respond to a WoL command if it is in a sleep mode.
  • I just tested it on a mini here at the museum. Does not wake from a shutdown state. only from a sleep state.

    Doesn't do me a whole lot of good when the museum wants them off for that whole being green thing.
  • Jorde_VJorde_V Posts: 393
    pdavis41 wrote: »
    I just tested it on a mini here at the museum. Does not wake from a shutdown state. only from a sleep state.

    Doesn't do me a whole lot of good when the museum wants them off for that whole being green thing.

    It consumes a watt in sleep state.
  • pdavis41 wrote: »
    Well we came across something huge (at least on a laptop as that was the mac we had on hand to test with).

    If you send a shutdown command to a mac. it will NOT wake up with WoL. It will only respond to a WoL command if it is in a sleep mode.

    I've found this too. I have a system that controls 30+ macs and at end of day I have the system reboot them (to give them a reset basically) and then put them to sleep.

    The firm that wrote the media software running on the macs also wrote a control interface which I don't have access to I'm afraid.
  • DHawthorneDHawthorne Posts: 4,584
    pdavis41 wrote: »
    I just tested it on a mini here at the museum. Does not wake from a shutdown state. only from a sleep state.

    Doesn't do me a whole lot of good when the museum wants them off for that whole being green thing.

    I find "this whole green thing" to be unbelievably annoying. The amount of power you waste leaving a Mac in sleep mode rather than full shutdown could probably be offset by turning one set of lights off a half hour early every day. People are absolutely rabid about tiny, miniscule savings, and utterly ignore the big issues that actually matter. You ever look at the impact of a single commercial airline flight compared to that of a car? Yet we go nuts squeezing every possible MPG out of an automobile, and how many airlines are replacing their fleets with more efficient planes?

    We are holding ourselves hostage to "feel good" measures that make people think they are doing some good. We need to be actually doing things that make a difference, not catering to political correctness.
  • I am of the same feeling. I am actually just going to start putting them to sleep as it works.

    I just find it annoying that a PC will wake from a off state with WoL and a Mac won't.

    Back to the topic on hand, I HATE having to do a login routine on telnet connections. Has anyone come across a way to make a telnet server on a mac unprotected? Security isn't a issue with the ones I'm controlling.
  • So I'm working on the telnet option of connecting to a mac.

    The mac is running OS X 10.6.8

    When I open the port to 23 of the macs ip I get back FF,FD,18,FF,FD,20,FF,FD,23,FF,FD,27,FF,FD,24.

    From what I have seen tooling around here it is the telnet negotiation. No luck on responding to it though with anything that anyone has posted before.

    Any thoughts?
  • AuserAuser Posts: 506
    pdavis41 wrote: »
    When I open the port to 23 of the macs ip I get back FF,FD,18,FF,FD,20,FF,FD,23,FF,FD,27,FF,FD,24.

    From what I have seen tooling around here it is the telnet negotiation. No luck on responding to it though with anything that anyone has posted before.

    Any thoughts?

    It's been a while since I wrote a module for telnet negotiation, but I seem to remember that it involves the two ends challenging each other to see what features they each support. Basically it boils down to the host you're connecting to making two types of statements:

    - Do <something> (ie. you implement this feature)
    - I Will <something> (ie. I'm going to implement this feature)

    All you need to do is send the appropriate response for "I won't" <do that> ($FC) and "don't" <do that> ($FE) respectively and no options will ever be implemented. As a result you get left with a plain text connection. Pretty simple stuff.

    * DO (x): decline with IAC WONT (x)
    * We don't know how to do that.
    * WILL (x): ask them not to with IAC DONT (x)
    * I don't know what you're talking about, so we'll ask you not to.

    My module acts as an interface to a socket connection and you just pass comms through it. Unfortunately I can't give it to you as it's not my IP to hand out :(

    However, the RFC for telnet is pretty straightforward, you just need to parse out any interpret as command responses (= $FF) and then look for either of the opcodes above (DO = $FD, WILL = $FB) following. The next byte is the option they want to implement.

    The first sequence in the above is "$FF,$FD,$18" = "'Interpret as command', DO, 'something' (who cares what, we're not going to implement it)".

    The response would be "$FF,$FC,$18" (hex obviously) = "'Interpret as command', WON'T, 'whatever it was you asked me to do'".
  • viningvining Posts: 4,368
    Here's a link to thread started a few years back that also discusses this telnet exchange.

    http://www.amxforums.com/showthread.php?6856-TELNET-commands&highlight=Telnet+session
  • Remote Shutdown of Macs - Revisited

    Hi Everyone,

    Designing a system for a museum, need to have AMX shutdown a bunch of Mac mini's that drive the various exhibits, wanted to revisit this topic and see if anyone has any updates or additional suggestions as to what works, preferably reliably and consistently!

    Think I have the boot thing covered - I've specified SurgeX iControl IP controllable outlet strips, which will allow the Macs to be booted/rebooted from full powered off or locked up states, by setting them to Auto Restart from AC Power loss. (As I understand it, Wake on Lan protocol works from some variation of a sleep state only, as the computers Network interface needs to be powered to allow it to respond to the Wake)

    Obviously, don't want to just yank the power to shut them down and corrupt data, need to trigger an orderly shutdown from AMX. As I undertstand it, and has been mentioned previously, know shutdown can be triggered from an SSH connection such as Apple Desktop Server, but I don't know if AMX can initiate SSH communications, or what other issues and considerations need to be taken into account.

    I've been programming AMX systems since the mid 90's, but my background is really AV, not hardcore programming, and while I'm good at parsing RS232 strings, etc, I'm still getting my feet wet w/ IP based control.
    Appreciate anyone who can share some wisdom &/or suggestions. Thanks so much!
  • the8thstthe8thst Posts: 470
    bobrivers wrote: »
    Hi Everyone,

    Designing a system for a museum, need to have AMX shutdown a bunch of Mac mini's that drive the various exhibits, wanted to revisit this topic and see if anyone has any updates or additional suggestions as to what works, preferably reliably and consistently!

    Think I have the boot thing covered - I've specified SurgeX iControl IP controllable outlet strips, which will allow the Macs to be booted/rebooted from full powered off or locked up states, by setting them to Auto Restart from AC Power loss. (As I understand it, Wake on Lan protocol works from some variation of a sleep state only, as the computers Network interface needs to be powered to allow it to respond to the Wake)

    Obviously, don't want to just yank the power to shut them down and corrupt data, need to trigger an orderly shutdown from AMX. As I undertstand it, and has been mentioned previously, know shutdown can be triggered from an SSH connection such as Apple Desktop Server, but I don't know if AMX can initiate SSH communications, or what other issues and considerations need to be taken into account.

    I've been programming AMX systems since the mid 90's, but my background is really AV, not hardcore programming, and while I'm good at parsing RS232 strings, etc, I'm still getting my feet wet w/ IP based control.
    Appreciate anyone who can share some wisdom &/or suggestions. Thanks so much!

    You should call and ask around AMX HQ. There are a couple guys there that programmed the system that controls all of the Apple Stores, and they should be able to give you some help.

    Your AMX rep might know somebody to contact to get you in touch with the right people too.
  • annuelloannuello Posts: 294
    If you do a "man shutdown" you will see that there is a -s option to put the Mac to sleep rather than turning it off. This may be useful in conjunction with WoL.
    (From the Mac command line)
    sudo shutdown -s now
    Password: ************
    
    Maybe a simple bargraph (in $$$ / Watts / black balloons of carbon) showing "Mac on 24/7" vs "Mac sleeping out of hours" would be enough to persuade the decision-makers that it is still green and making a difference. It may be helpful to show the negligible difference between sleep or off, but I suppose that depends on how obsessed the decision-makers are. If a Mac consumes too much power in standby do they want you to turn off the control system and controllable outlet strips as well? How about the alarm? :)

    Just my 2-bits worth. All the best with it.
    Roger McLean.
  • PhreaKPhreaK Posts: 966
    Nice thinking on placing the box's on switchable points and setting the autoboot on power. Setting up an SSH connection to the target machines to initiate a shutdown is definitely do-able. It's not necessarily a simple process though, particularly if you want to implement it all in NetLinx. Have a search of the forums as its been discussed a couple of times in the past.

    For you situation an alternative that may be worth investigating is rolling a little utility app that runs on the exhibit machines. As having the machines operational is a I'm guessing a rather important aspect of the system this will allow you to not only expose an API for power control but also some basic monitoring. For security you can then lock this to only accept a socket connection from your NetLinx box that interfaces with it.
Sign In or Register to comment.