Page 1 of 2
How to power off from command line?
Posted: Tue Nov 20, 2018 5:23 pm
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
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).
halt after shutdown?! power down ...otherwise halt?
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
Re: Best way to power off from command line?
Posted: Tue Nov 20, 2018 5:26 pm
by clicktician
I routinely use (as root):
Of course, I'm routinely wrong. Lol.
Re: Best way to power off from command line?
Posted: Tue Nov 20, 2018 5:35 pm
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" ;;
Re: Best way to power off from command line?
Posted: Thu Nov 22, 2018 4:58 pm
by Vincent17
Thanks for the replies.
@clicktician shutdown seemed to offer the best solution for me. I used
(as in powerbtn-acpi-support.sh script).
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.
Re: Best way to power off from command line?
Posted: Mon Feb 04, 2019 6:18 pm
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.
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
Re: How to power off from command line?
Posted: Mon Feb 04, 2019 6:41 pm
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)?
Re: How to power off from command line?
Posted: Mon Feb 04, 2019 9:06 pm
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.
Re: How to power off from command line?
Posted: Mon Feb 04, 2019 9:28 pm
by figueroa
Why not just "sudo halt?"
Re: How to power off from command line?
Posted: Fri Feb 08, 2019 8:35 pm
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
Re: How to power off from command line?
Posted: Fri Feb 08, 2019 9:32 pm
by Gordon Cooper
figueroa wrote: ↑Mon Feb 04, 2019 9:28 pm
Why not just "sudo halt?"
This works perfectly - less typing too!