Is it possible to set some sort of script that automaticly turns off the computer at certan time, for example at 10pm. I am running Ubuntu 18.04

  • It is unclear if you want to do it once or daily.
    – Pilot6
    Jan 30, 2020 at 16:14
  • @Pilot6 scripts tend to be re-usable :)
    – Rinzwind
    Jan 30, 2020 at 16:15
  • Well, your solution does it once, mine daily. That's why I am asking.
    – Pilot6
    Jan 30, 2020 at 16:16

3 Answers 3


You can add

0 22 * * * root poweroff

to /etc/crontab

That will turn off computer daily at 10pm.

  • Can you explain me the process step by step? Jan 30, 2020 at 16:15
  • Open the file e.g. by nano sudo nano /etc/crontab and add the line there below everything else. Ctrl+X to exit.
    – Pilot6
    Jan 30, 2020 at 16:15
  • I should add 0 22 * * * root poweroff to /etc/crontab in script made from notepad, shold't I? In which format should I save the script? Or i can just run it in the terminal? Jan 30, 2020 at 16:21
  • 1
    You don't add a script. You run in a terminal sudo nano /etc/crontab, the file will open, and you add the line to the text file.
    – Pilot6
    Jan 30, 2020 at 16:22
  • 1
    Ask another question with details on what are the computers, what are you doing and what happens.
    – Pilot6
    Feb 25, 2020 at 22:17

Yes. The shutdown command allows for a delayed action.

shutdown -h 22:00

shuts the system down at 22:00 IF the system is running.

shutdown -r +1440

will shutdown in 24 hours (1440/60=24) so tomorrow at the current time.

If you want more elaborate methodes install at. That allows things like "at sunday", or "next week", "now + 120 min" and so on.

These commands need to be repeated every time you want this. Follow pilot6's answer to add a command to cron. If you use commands make sure to use absolute paths.


For example you could use a crontab: enter sudo crontab -e (this opens the crontab file for the root user) At the end on a new line you enter the following(it will shutdown the computer at 22PM):

0 22 * * * shutdown -P now >/dev/null 2>&1

This will shutdown The Syntax is:

* * * * * COMMAND

Beforte the command there are 5 thins to give: 1. Minute, 2. Hour, 3. Day of Month, 4. Month, 5. Day of Week. All have to be true. If you put a star it accepts every value there. So you could also say execute a command at 7 AM, if it is a Friday the 13th: 0 7 13 * 5 /alert.sh

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.