How can I force Linux to shut down or block access at bedtime?
Asked by
MellowCedar42
I'm using Linux Mint and have trouble stopping computer use at night, which often leads to going to sleep around 3:00 AM. Alarms and reminders haven't helped because I simply ignore them. I'm looking for a stronger solution, such as automatically shutting the computer down at a set time and preventing it from staying available during certain hours. Are there any applications, scripts, or system tools that can help enforce a schedule?
Answers
If you want to prevent simply turning the computer back on and continuing, use a script that checks the current time and powers off whenever it runs during restricted hours. A cron job checking every couple of minutes can enforce a window such as 11 PM through 6 AM. Keep in mind that anyone with administrator access can disable or edit the script, so combining it with practical habitsโlike placing alarms away from the deskโmay make it more effective.
Reply to this answer
For a simple countdown, create a script like this and run it when you want the timer to begin: `#!/bin/bash` followed by `sleep 3600` and then `poweroff`. That waits one hour and shuts down the computer. You could also use a systemd timer or cron job to run it at a particular clock time.
Reply to this answer
A scheduled shutdown can be set up with cron. Open the root crontab with `sudo crontab -e`, then add a line such as `45 22 * * * /sbin/shutdown -h now` to shut the machine down every day at 10:45 PM. Be aware that unsaved work will be lost.
Reply to this answer
Workrave may be worth trying. It can remind you to take breaks and also enforce a daily usage limit. Itโs free, so itโs an easy option to test.
Reply to this answer
Add your answer
Answers are reviewed before publication.
CopperVale31: You can add a warning before shutdown by inserting a notification command between two waitsโfor example, wait an hour, display โTurning off in five minutes,โ wait another 300 seconds, and then run `poweroff`.