3

I'd like to schedule a shutdown every day at a specific time for my system. I found this post that addresses this, but I can't find rc.local I looked around and it seems like this file doesn't exist on Ubuntu 20.04 I was wondering what the best way to solve this problem is? Should I create this file or is there a file that "substitutes" it?

PS: currently the answers to my question mention cron. However, I found the accepted answer to this post that recommends not using cron for shutdown. I was wondering if someone could elaborate on this option too and why it is not / or is a good option

5

2 Answers 2

3

With a quick search, I hopefully found the answer you're looking for

Automatic shutdown at specified times?

" Cron will work very well for this.

Add the below line (with tweaks) to the end of /etc/crontab:

30 23 * * * root shutdown -h now "

From: Automatic shutdown at specified times?

Reply if it worked! Good luck!

To run sample.sh twice a day. say 5am and 5pm

0 5,17 * * * shutdown.sh

where shutdown.sh has the contents

shutdown

  • Or, if you want another way:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
  0 0 * * 0 root      /sbin/shutdown -h now # power off every sunday at 00:00 am

Or, alternativly you can use: sudo crontab -e and enter 0 0 * * 0 root /sbin/shutdown -r now

References:

4
  • In case it needs step by step explanation: edit the crontab (nano /etc/crontab) or (gedit /etc/crontab) and type 30 23 * * * root shutdown -h now " to the file's end. for example. Sep 30, 2020 at 14:19
  • Here we got 1 more (Ill add this to my answer) (Hopefully helpful for the future) askubuntu.com/questions/538639/shutdown-530pm-every-day?rq=1 Sep 30, 2020 at 14:30
  • Thanks for the answer. I just added a PS note to my question. Was wondering if you could update your answer accordingly Sep 30, 2020 at 16:19
  • I don't have a file called crontab Oct 1, 2020 at 0:56
0
  1. In Ubuntu 20.04 you can execute crontab -e, then enter your command at the bottom of the text lines.
    • use cron command syntax, it can be viewed at man cron.
  2. You can use the "Crontab Generator" on this url https://crontab-generator.org/ to calculate your command parameters.
2
  • Thanks for the answer. I just added a PS note to my question. Was wondering if you could update your answer accordingly Sep 30, 2020 at 16:19
  • i just looked up around some forums and i did not find any comments about not using cron, just few more Q&A and recommend to use it.
    – johncli
    Sep 30, 2020 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .