How can I force my Linux computer to shut down at night?
Asked by
sand dune survey+~
I'm using Linux Mint and have trouble stopping computer use at a reasonable hour. Reminders and alarms are too easy for me to ignore, so I'm looking for a more enforceable solutionโideally something that shuts the computer down at a chosen time, such as 11 PM, and possibly prevents it from staying on during overnight hours. What software, scripts, cron jobs, or other methods would work?
Answers
A cron job can shut the machine down at the same time every night. Run `crontab -e` and add a line such as `45 22 * * * /sbin/shutdown -h now` to shut down daily at 10:45 PM. Make sure you save your work first, since this wonโt give applications much opportunity to recover unsaved data.
Reply to this answer
Workrave may be worth trying if you want something less drastic. It can remind you to take breaks and enforce a daily usage limit. Unlike a normal alarm, it can make the limit harder to casually dismiss, though a determined user can still disable almost any software restriction.
Reply to this answer
The technical solution can help, but itโs also useful to add a physical barrier. Put a separate alarm or timer somewhere that requires you to get up and leave the computer to turn it off. Combining that with an automatic shutdown gives you both an external reminder and a consequence thatโs harder to ignore.
Reply to this answer
For a simple one-time limit, a small Bash script is enough: `sleep 3600` followed by `poweroff` will shut the computer down after an hour. You could add a warning beforehand, such as a desktop notification five minutes before shutdown, and then give yourself time to save anything important.
Reply to this answer
You can make the shutdown conditional so the computer is turned off throughout a blocked period. For example, a script can check whether the current hour is between 11 PM and 6 AM and run `/sbin/poweroff` during that window. A root cron job running every couple of minutes could enforce it even if the computer is restarted during the restricted hours. Be careful with permissions and test the script before relying on it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions