12 Comments

Power Management from the Command Line

To be able to invoke commands like suspend and hibernate from the command line not so long ago required having root privileges or using the desktop environment built-in tools. Now to invoke suspend, hibernate, shutdown, or restart, D-Bus can be invoked as Regular user. I created a script called pwrman to ease the task (requires UPower to be installed).

(I got this idea from a person from the Arch Linux forums. I forgot who you are, so sorry, but thank you.)

About these ads

About Todd Partridge (Gently)

Good times, good people, good fun.

12 comments on “Power Management from the Command Line

  1. #!/usr/bin/env bash

  2. Something is not right, copy and pasted, and I got:
    % bash pwrman shutdown
    pwrman: line 4: filename: command not found
    pwrman: line 6: $’case\302\240shutdown\302\240in’: command not found
    pwrman: line 7: syntax error near unexpected token `)’
    pwrman: line 7: ` shutdown )’

    Can you give a wgeteable link? But the idea is very useful.

  3. DBus? Urgh, how many millions of lines code were used to do something relatively simple?

    This isn’t in keeping with the Arch philosophy. Come on, do better!

  4. @ Kazuo

    Can you give a wgeteable link? But the idea is very useful.

    Sure:

    wget http://pastebin.com/download.php?i=9EMhQSg6 -O pwrman

    Something is not right, copy and pasted, and I got:

    % bash pwrman shutdown
    pwrman: line 4: filename: command not found
    pwrman: line 6: $'case\302\240shutdown\302\240in': command not found
    pwrman: line 7: syntax error near unexpected token `)'
    pwrman: line 7: `  shutdown  )'

    Not sure about this. Could it have something to do with your shell? This is pretty basic bash syntax.

    @ Kai Hendry

    DBus? Urgh, how many millions of lines code were used to do something relatively simple?

    This isn’t in keeping with the Arch philosophy. Come on, do better!

    Actually, I had this script gotten before from the Arch forums, but the commands needed updating and I found them on the Arch Wiki. Invoking dbus, this is as good as it gets.

    @ Derek Schrock

    #!/usr/bin/env bash

    Eh?? I’ve seen this before but sometimes in older scripts. Doesn’t seem to be the common way to do things anymore. Any reason I should be using this syntax?

  5. What about `sudo halt` & `sudo reboot` or just making sure the physical buttons work on the PC?

  6. @ Kai Hendry

    What about `sudo halt` & `sudo reboot` or just making sure the physical buttons work on the PC?

    Yeah, I hear you. I basically thought this solution was useful because of having to call sudo and entering a password to something I had physical access to just seeming unnecessary to me. My basic use for it is usually to suspend quickly when doing work from the command line which I often do. Perhaps using dbus doesn’t make the prettiest looking script, but it does work nice and I expect it to be around awhile.

  7. Sure, that does a good job. I find that I reinstall from time to time so having this script around work a bit better for me.

  8. @Todd
    Thanks. Solved. The problem come from the copy/paste it copied some non-space spaces.

  9. Hey, nice script thanks. :-) I thinking about using it in combination with i3.
    If you use the script don’t forget to use a dbus-session. Will likely not work without one.

  10. Works in Ubuntu beta, thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: