public
Last active

Suspend, hibernate, restart or shutdown the computer without sudo!

  • Download Gist
power.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/bin/sh
 
# Suspend, hibernate, restart or shutdown the computer without sudo!
# by Chris Wong
# Released to the public domain.
 
NAME=$0
 
usage() {
echo "Usage: $NAME suspend|hibernate|restart|shutdown"
exit 42 # :D
}
 
if [ $# -ne 1 ] ; then
usage
else
THINGY_UPOWER="dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower"
THINGY_CONSOLEKIT="dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager"
case $1 in
suspend)
$THINGY_UPOWER org.freedesktop.UPower.Suspend
;;
hibernate)
$THINGY_UPOWER org.freedesktop.UPower.Hibernate
;;
restart)
$THINGY_CONSOLEKIT org.freedesktop.ConsoleKit.Manager.Restart
;;
shutdown)
$THINGY_CONSOLEKIT org.freedesktop.ConsoleKit.Manager.Stop
;;
*)
usage
;;
esac
fi

Requires authentication as of Ubuntu 12.04.

@tenleftfingers I'm using 12.04 right now, and I've never had to authenticate. It should act as though you chose the corresponding option in the GUI. Screenshot?

I have the same authorization problem:

Error org.freedesktop.ConsoleKit.Manager.NotPrivileged: Authorization is required

I'm trying to resolve this but with no success.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.