Welcome!
Important information
-- Information on torrent hosting changes
-- Information on MX15/16 GPG Keys
-- Spectre and Meltdown vulnerabilities

News
-- Introducing our new Website
-- MX Linux on social media: here

Current releases
-- MX-18.1 Point Release release info here
-- Migration Information to MX-18 here
-- antiX-17.4 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

How 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.
Vincent17
Forum Novice
Forum  Novice
Posts: 61
Joined: Tue Feb 20, 2018 1:07 am

How to power off from command line?

#1

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

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
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: 636
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: 61
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
(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
Forum Novice
Forum  Novice
Posts: 61
Joined: Tue Feb 20, 2018 1:07 am

Re: Best way to power off from command line?

#5

Post by Vincent17 » Mon Feb 04, 2019 6:18 pm

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
** sysrq script

Code: Select all

sync
echo password | sudo -S xfce4-terminal -x bash -c "echo o > /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

User avatar
Fibogacci
Forum Novice
Forum  Novice
Posts: 52
Joined: Sun Dec 30, 2018 4:19 pm

Re: How to power off from command line?

#6

Post by Fibogacci » Mon Feb 04, 2019 6:41 pm

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
---
MX-18 386/antiX-17 386: desktop Dell OptiPlex GX240, Intel Pentium 4 1794 MHz, 256MB-1GB SD-RAM PC133, Kernel: 4.19/4.20, DE: Xfce

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

Re: How to power off from command line?

#7

Post by Vincent17 » Mon Feb 04, 2019 9:06 pm

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
Forum Regular
Forum Regular
Posts: 210
Joined: Fri Dec 21, 2018 12:20 am

Re: How to power off from command line?

#8

Post by figueroa » Mon Feb 04, 2019 9:28 pm

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

User avatar
KoO
Forum Regular
Forum Regular
Posts: 458
Joined: Fri Feb 10, 2017 1:21 am

Re: How to power off from command line?

#9

Post by KoO » Fri Feb 08, 2019 8:35 pm

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.
AntiX 17.3 (4.20.12) i3 ,MX18 (4.19.13),windows8.1 , Intel Xeon E3-1241 v3 , 16gb HyperX , EVO 860 500 GB , EVO 860 500 GB , GTX 970 :linuxlove:
Lenovo T430 AntiX17.3 (4.20) i3 ,MX18 (4.19.13),windows8.1 , i5 +4000 , 8gb , EVO 860 500 GB , 1TB HGST

User avatar
Gordon Cooper
Forum Guide
Forum Guide
Posts: 2295
Joined: Mon Nov 21, 2011 5:50 pm

Re: How to power off from command line?

#10

Post by Gordon Cooper » Fri Feb 08, 2019 9:32 pm

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

Post Reply

Return to “Tips&Tricks”