Does GNU/Linux keep a log of when the machine and/or monitor was turned on?

I wish to limit my screen time by telling the machine to automatically hibernate 90 minutes after the last startup or awake. This precludes using @reboot, I think, and I don't think cron has an @awake parameter. Currently, systemctrl suspend runs every X minutes, even when the current session is is less than 90 minutes.

  • Is there a reason the task can not be a part of system startup or user login scripts? System startup and sleep/wakeup events tend to be logged in the system's logs (use journalctl on systemd systems or check /var/log/ to read the logs). – Mio Rin Apr 6 '19 at 4:36
  • User login might be a partial solution, but I don't want the script to reset because I locked it or because the monitor went to sleep. The ideal is to track uptime / time since last awake or start. @reboot won't work for reasons stated above. I have looked journalctl and /var/log, but there's a lot there. Can you specify? – zadrozny Apr 6 '19 at 13:40
  • 1
    may be related askubuntu.com/q/68918/10473 – ctrl-alt-delor Apr 6 '19 at 15:09

This looks like an XY problem, I have an alternate solution.

For the machine startup. You can run a start up script, and use a sleep to delay the rest of the script.

You can probably do similar by attaching and script to an event for monitor on.

Edit following OP adding reason.

I think there are programs to help you limit screen time. I added a link to a related question to comments.

  • Thanks. I am still holding out hope that the I can do this in a one-line script, based on information from a log. – zadrozny Apr 6 '19 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.