Welcome!
Important information
-- Spectre and Meltdown vulnerabilities

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-18 Final release info here
-- Migration Information to MX-18 here
-- antiX-17.3 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

Best way to power off from command line?

Just as the name says, here is where you can post tips and tricks to share with other users of MEPIS.
Post Reply
Vincent17
Forum Novice
Forum  Novice
Posts: 50
Joined: Tue Feb 20, 2018 1:07 am

Best way to power off from command line?

#1

Post by Vincent17 » Tue Nov 20, 2018 5:23 pm

Hello,
What is the recommended way to power off the computer from command line or script?
I have been using "xfce4-session-logout --halt", but I'm confused about the meaning of "halt".
  • xfce4-session-logout --halt
    systemctl poweroff
    sudo poweroff
    sudo shutdown -P now
    others?
I haven't been able to track down what Log Out gui "Shut Down" button does, although most likely it uses --halt: https://forum.xfce.org/viewtopic.php?id=11735

systemctl poweroff is appealing because its meaning seems clear, but I think systemctl is from systemd, so although it works in MX, it is not available in antiX. poweroff itself requires sudo so it's not good in a script.

Code: Select all

shutdown --help
shutdown: you must be root to do that!
Usage:	  shutdown [-akrhPHfFnc] [-t sec] time [warning message]
		...
		-h:      halt after shutdown.  					
		-P:      halt action is to turn off power.  
		-H:      halt action is to just halt.
		...
halt --help
		...	
		-p: power down the system (if possible, otherwise halt).
:eek: halt after shutdown?! power down ...otherwise halt? :confused: What does "xfce4-session-logout --halt" mean?

Thanks in advance.

P.S. xfce4-session-logout --halt has always worked on an HP laptop with MX-17 x64. On an old MSI netbook running MX 17.1_386, occasionally the computer winds up unresponsive but still on.
https://askubuntu.com/questions/771166/ ... e-terminal

clicktician
Forum Regular
Forum Regular
Posts: 227
Joined: Sat May 02, 2015 4:35 pm

Re: Best way to power off from command line?

#2

Post by clicktician » Tue Nov 20, 2018 5:26 pm

I routinely use (as root):

Code: Select all

shutdown -h now
Of course, I'm routinely wrong. Lol.
Son, someday all this will belong to your ex wife.

User avatar
oops
Forum Regular
Forum Regular
Posts: 513
Joined: Tue Apr 10, 2018 5:07 pm

Re: Best way to power off from command line?

#3

Post by oops » Tue Nov 20, 2018 5:35 pm

Or (as user):

Code: Select all

cmd="dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true" ;;
$ inxi -Fxxxz : System: Host:XEON ... Distro: MX-18_x64 Continuum

Vincent17
Forum Novice
Forum  Novice
Posts: 50
Joined: Tue Feb 20, 2018 1:07 am

Re: Best way to power off from command line?

#4

Post by Vincent17 » Thu Nov 22, 2018 4:58 pm

Thanks for the replies.
@clicktician shutdown seemed to offer the best solution for me. I used

Code: Select all

sudo shutdown -h -P now
in my script (as in powerbtn-acpi-support.sh script). :frown: Unfortunately, the computer still ends up in a halt state (dead but power still on--have to press power button 5 seconds to turn it off).

@oops Mercy!! That's intimidating, but I love that it clearly says PowerOff :) Have added "learn about dbus-send" to my list. Same result, though, with your syntax (the stuff within the quotes): computer halts, does not power off.

At this point I think it's likely a quirk of the computer, a 10+ year old MSI netbook.

I asked about "xfce4-session-logout --halt" on the xfce4 forum; no answers yet.

Y.A.Edit: systemctl poweroff, busybox poweroff -f also don't work :frown:

Code: Select all

sudo halt -fihp
has worked several times in a row! (immediate abrupt poweroff :happy:

Post Reply

Return to “Tips&Tricks”