How to power off from command line?

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Message
Author
Vincent17
Posts: 75
Joined: Tue Feb 20, 2018 1:07 am

How to power off from command line?

#1 Post by Vincent17 »

EDIT: I changed the title since the nature of the question changed. See 5th post for a summary.
Should now be in hardware forum section; maybe a list of too many poweroff commands can be considered a tip :rolleyes:

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
Last edited by Vincent17 on Tue Feb 05, 2019 4:30 pm, edited 3 times in total.

clicktician
Posts: 136
Joined: Sat May 02, 2015 4:35 pm

Re: Best way to power off from command line?

#2 Post by clicktician »

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
Posts: 1602
Joined: Tue Apr 10, 2018 5:07 pm

Re: Best way to power off from command line?

#3 Post by oops »

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" ;;
Pour les nouveaux utilisateurs: Alt+F1 pour le manuel, ou FAQS, MX MANUEL, et Conseils Debian - Info. système “quick-system-info-mx” (QSI) ... Ici: System: MX-19_x64 & antiX19_x32

Vincent17
Posts: 75
Joined: Tue Feb 20, 2018 1:07 am

Re: Best way to power off from command line?

#4 Post by Vincent17 »

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

Code: Select all

sudo shutdown -h -P now
(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.

I asked about "xfce4-session-logout --halt" on the xfce4 forum and got one answer suggesting it calls systemctl --halt.

Vincent17
Posts: 75
Joined: Tue Feb 20, 2018 1:07 am

Re: Best way to power off from command line?

#5 Post by Vincent17 »

After 2+ months and 1000 reboots ::), I have not found a reliable poweroff method for the MSI Wind U100, so I'll bump a last time to see if anyone has a suggestion. 9_9
The problem is that the computer sometimes halts with power still on; power button must be held down for 5 s to power off. If unattended, it gets hot and runs the battery down.
Summary of what I've tried: (*=often fails to poweroff MSI Wind, **=occasionally fails to poweroff)
* xfce4-session-logout --halt and --halt --fast
* /sbin/shutdown -hP now
* /sbin/halt -p (= /sbin/poweroff)
* systemctl poweroff --force
* systemctl start poweroff.target
* dbus commands (above)
* reboot(RB_POWER_OFF) in c++ ( here)
>It did not help to blacklist dw_mac modules (/etc/modprobe.d/hang-on-shutdown.conf)
** busybox poweroff -f
** /sbin/halt -fihp
** init 0
** echo o | sudo tee /proc/sysrq-trigger


System: Host: wind Kernel: 4.15.0-1-686-pae i686 bits: 32 Desktop: Xfce 4.12.3
Distro: MX-18_386 Continuum March 12 2017
Machine: Type: Desktop System: MICRO-STAR product: U-100 v: Ver.001 serial: <root required>
Mobo: MICRO-STAR model: U-100 v: Ver.001 serial: <root required>
BIOS: American Megatrends v: 4.6.3 date: 07/16/2008
Battery: ID-1: BAT1 charge: 7.7 Wh condition: 17.7/24.4 Wh (72%)
CPU: Single Core: Intel Atom N270 type: MT speed: 863 MHz min/max: 800/1600 MHz
Graphics: Device-1: Intel Mobile 945GSE Express Integrated Graphics driver: i915 v: kernel
Display: x11 server: X.Org 1.19.2 driver: intel unloaded: fbdev,modesetting,vesa
resolution: 1024x600~60Hz
OpenGL: renderer: Mesa DRI Intel 945GME x86/MMX/SSE2 v: 1.4 Mesa 18.2.6
Network: Device-1: Realtek RTL8101/2/6E PCI Express Fast/Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8187SE Wireless LAN driver: rtl818x_pci
Drives: Local Storage: total: 126.33 GiB used: 71.50 GiB (56.6%)
Info: Processes: 188 Uptime: 4m Memory: 1.96 GiB used: 275.2 MiB (13.7%) Shell: bash
inxi: 3.0.29
Last edited by Vincent17 on Sat Jan 28, 2023 7:51 pm, edited 1 time in total.

User avatar
Fibogacci
Posts: 165
Joined: Sun Dec 30, 2018 4:19 pm

Re: How to power off from command line?

#6 Post by Fibogacci »

hello,

well, maybe this one could work:

$ sudo telinit 0

more info:
http://www.linfo.org/runlevel_def.html

edit:
Is the problem still exist with another Linux distro? Or for example with Live CD/USB Linux (MX or antiX)?
MX-18 Continuum x86_64: laptop Dell Inspiron N7110, Intel Core i5-2410M @ 2.900GHz, 4GB RAM, Kernel: 4.19, DE: Xfce

Vincent17
Posts: 75
Joined: Tue Feb 20, 2018 1:07 am

Re: How to power off from command line?

#7 Post by Vincent17 »

Thanks Fibogacci, I'll give telinit 0 a try. [edit: /sbin/telinit -> init so I expect it will eventually fail, as init 0 did] I never had this problem in years of using Puppy Linux (shutdown by busybox poweroff -f, I think, older kernel). I haven't given antiX a good try on this computer. I only booted from live usb a couple of times--inconclusive.
Last edited by Vincent17 on Tue Feb 05, 2019 11:50 am, edited 1 time in total.

User avatar
figueroa
Posts: 1049
Joined: Fri Dec 21, 2018 12:20 am

Re: How to power off from command line?

#8 Post by figueroa »

Why not just "sudo halt?"
Andy Figueroa
Using Unix from 1984; GNU/Linux from 1993

User avatar
KoO
Posts: 491
Joined: Fri Feb 10, 2017 1:21 am

Re: How to power off from command line?

#9 Post by KoO »

If you ever just want to logout from the command line do this = tested working
sudo pkill -u username

(sudo pkill -u koo)

sudo halt = shutdown
sudo reboot = reboot
sudo pkill -u username = logout to log on screen
Last edited by KoO on Fri Feb 08, 2019 10:07 pm, edited 1 time in total.
Main : MX 19.1-AHS (i3) 5.4.13-1~mx19+1, Asus B450-i AMD 5 3600 , 32gb Hyper-X 3200 , GTX970 . :linuxlove:
Lenovo T430 : Debian10 antiX17 (i3) , 4.20.12 , i5 , 12gb .
Lenovo X220 : Test Machine (ATM)

User avatar
Gordon Cooper
Posts: 965
Joined: Mon Nov 21, 2011 5:50 pm

Re: How to power off from command line?

#10 Post by Gordon Cooper »

figueroa wrote: Mon Feb 04, 2019 9:28 pm Why not just "sudo halt?"
This works perfectly - less typing too!
Backup: Dell9010, MX-19_B2, Win7, 120 SSD, WD 232GIB HD, 4GB RAM
Primary :Homebrew64 bit Intel duo core 2 GB RAM, 120 GB Kingston SSD, Seagate1TB.
MX-18.2 64bit. Also MX17, Kubuntu14.04 & Puppy 6.3.

Post Reply

Return to “Tips & Tricks by users”