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.)
Cool
#!/usr/bin/env bash
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.
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!
@ Kazuo
Sure:
Not sure about this. Could it have something to do with your shell? This is pretty basic bash syntax.
@ Kai Hendry
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
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?
What about `sudo halt` & `sudo reboot` or just making sure the physical buttons work on the PC?
@ Kai Hendry
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.
Use the NOPASSWD sudo keyword in your `/etc/sudoers`.
DBus is to be avoided. It sucks.
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.
@Todd
Thanks. Solved. The problem come from the copy/paste it copied some non-space spaces.
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.
Works in Ubuntu beta, thanks.