Script to force shutdown

I want to have a app which can shutdown the system (10.7.2) by force (without any interuption). I do this with "sudo shutdown -h now" on Terminal (on my computer).


Now, I want to have shutdown app for my parents system (and it shouldn't prompt for asking password).


Can you suggest me the script which can shutdown forcefully (usually skype call runs in the backround).

Mac mini, Mac OS X (10.7.2)

Posted on Nov 14, 2011 12:52 PM

Reply
4 replies

Nov 14, 2011 9:16 PM in response to chittu

You can't force a shutdown without an administrator's password, so either your script is going to need to prompt, or you'll need to embed your admin password in your script (which leaves it vulnerable since scripts are not encrypted by default).


Something like:


do shell script "/sbin/shutdown" user name "admin" password "supersecret" with administrator privileges


Omit the 'password' parameter to have the OS prompt for the admin credentials at runtime.


You could also edit /etc/sudoers to give your standard user's unfettered access to /sbin/shutdown without requiring a password, but that's an even hairier prospect in my book.

Nov 15, 2011 5:58 AM in response to chittu

Another trick is setting up a no-passphrase ssh-keygen key for the root account, then putting the root's public ssh key in the normal account's .ssh/authorized_keys file. Now you can "ssh root@localhost /sbin/shutdown -h now"


NOTE: It is NOT necessary to enable the root account to use this trick. You can become root via "sudo su -" and then perform the necessary ssh-keygen setup all without enabling root.


However, it is on par with Camelot's suggestion about /etc/sudoers, and at least Camelot's sudoers suggestion limits the destructive damage that can be done.

Nov 15, 2011 4:04 PM in response to Camelot

thanks Camelot for the elegent solution, the following command works well with embeded password in the script


Camelot wrote:


do shell script "/sbin/shutdown -h now" user name "admin" password "supersecret" with administrator privileges

However, removing the parameter "password" led to "Authorization failed" (it doesn't prompt for the password). Any fix for this?


Also, thanks to BobHarris, still I didn't try your suggestion but I'll (my system already has ssh-key with password protection, so I'll try in parents system).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Script to force shutdown

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.