2

I am trying to find a way to query the state of my laptop from the terminal. I would like to know if it is asleep or awake.

Is there a dbus query suitable for this?

  • What do you mean by asleep? well when you start typing it's active... – Ravexina Mar 28 '18 at 20:40
  • @Ravexina I plan to query this in a background service. – Senior-Jesticle Mar 28 '18 at 20:42
  • 4
    Still I can't get what do you mean by asleep, you can get the IDLE time using `xprintidle`, when your PC is sleep, well it's off, it can't do anything. – Ravexina Mar 28 '18 at 20:43
  • 2
    Sleep mode suspends the system to RAM so nothing is running. You would not be able to connect to your system in sleep mode, unless you had WOL (Wake On LAN) configured to wake the system back up so you could use it. It sounds to me that you would not be able to see if your system is asleep as it would wake up once you connected to it. See: https://en.wikipedia.org/wiki/Sleep_mode – Terrance Mar 28 '18 at 21:14
  • 1
    This is like asking your roommate whether he's asleep. Assuming he doesn't lie, there's no way he'd ever answer yes. – Byte Commander Mar 28 '18 at 23:06
  • 2
    Reviewers: Although this question does appear to hinge on a misunderstanding of what sleep mode entails, this can be addressed in an an answer, which would answer the question. @Terrance Can you post something like that comment as an answer? – Eliah Kagan Mar 29 '18 at 20:36
  • You can have your laptop keep a record off all sleep periods. But you would have to wake it up in order to ask it if it was just sleeping a few seconds ago. – WinEunuuchs2Unix Mar 29 '18 at 21:47

1 Answers1

5

Sleep mode on a computer suspends its current state to the RAM. The computer will then go into a low power mode keeping enough power going to the RAM to keep the suspended state. No applications are running at this time.

To wake the computer back up from a remote session would have to be done by a WOL (Wake On LAN) which is controlled by the motherboard. This would then wake the system back up. ssh daemons would not be running at the time the system is asleep so you would not be able to connect to the host that way. Once the magic packet is sent to WOL, the system would no longer be in the sleep state so the answer would be false every time for sleep.

See https://en.wikipedia.org/wiki/Sleep_mode for more information.

There would be one other way to find out if a system is powered on or not from a remote console but that requires special hardware that supports Out-of-band Management that is normally built into server hardware. There are some remote power management items that can be purchased for systems without the management, but they can be pricey and only control the power itself. Here are some that I did a quick search for.

Hope this helps!

Terrance
  • 39,774
  • 7
  • 116
  • 176