this post was submitted on 06 Feb 2025
32 points (97.1% liked)

Linux

49701 readers
1728 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I'm looking for a reliable way to log when my laptop is:

  • powered down
  • boots up
  • goes to sleep
  • wakes up

Currently I'm checking both the systemd-suspend and tlp systemctl services, but these don't really feel very robust, and I don't have TLP installed on all my machines.

Is there an easier way to do this, or a better systemctl unit that logs all the power states of my machine. Preferably laptop agnostic?

Laptop snippet so far:

journalctl --since -9days -u systemd-suspend -u tlp \
    | grep -P "Finish|Start|Stopped" | sed '/.*Finished TLP.*/d;
            s|Starting TLP.*|╭╴System Boot  |;
 s|Starting System Suspend.*|┤ · Sleep      |;
 s|Finished System Suspend.*|├ · Wake       |;
             s|Stopped TLP.*|╰╴Power Off    |;' \
    | sed -r 's|^(.*:[0-9]+)+:[0-9]+.*:(.*)|   \1 \2 |'
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 4 hours ago* (last edited 4 hours ago)

For boot and power down, create a service to log it.

For the others, an elogind script might be what you look for.