Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Suspend, hibernate, restart or shutdown the computer without sudo!
#!/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
@tenleftfingers

This comment has been minimized.

Show comment Hide comment
@tenleftfingers

tenleftfingers Jan 16, 2013

Requires authentication as of Ubuntu 12.04.

Requires authentication as of Ubuntu 12.04.

@lfairy

This comment has been minimized.

Show comment Hide comment
@lfairy

lfairy Jan 24, 2013

@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?

lfairy commented Jan 24, 2013

@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?

@chyl

This comment has been minimized.

Show comment Hide comment
@chyl

chyl Mar 5, 2013

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.

chyl commented Mar 5, 2013

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.

@linuxuser600

This comment has been minimized.

Show comment Hide comment
@linuxuser600

linuxuser600 Sep 9, 2015

I know this is a few years old but the script still works great. As an FYI for anyone who is using this script make sure you make the .sh file executable by going to the directory in the terminal and typing sudo chmod +x power.sh. It will not work and will "Require Authentication" if you do not.

I know this is a few years old but the script still works great. As an FYI for anyone who is using this script make sure you make the .sh file executable by going to the directory in the terminal and typing sudo chmod +x power.sh. It will not work and will "Require Authentication" if you do not.

@lfairy

This comment has been minimized.

Show comment Hide comment
@lfairy

lfairy Oct 30, 2015

On machines with systemd, systemctl {suspend|hibernate|reboot|poweroff} works as well.

lfairy commented Oct 30, 2015

On machines with systemd, systemctl {suspend|hibernate|reboot|poweroff} works as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment