2

Hello I just setup a ubuntu server running samba and I want it to shut down every night at 11PM.

This is what's in my crontab I'm using this command in crontab 30 9 * * * root shutdown -h now

Cron tab does seem to be on but its not running the command at the desired time.

Thanks in advance!

Paperboypaddy
  • 21
  • 1
  • 5
  • You have to use cron, check out my link... – Ravexina Aug 14 '18 at 01:10
  • @Ravexina Your duplicate is better! :) – WinEunuuchs2Unix Aug 14 '18 at 01:11
  • 2
    Welcome to Ask Ubuntu! Could you please add a little more detail? "It doesn't work" doesn't help a bit in the diagnosis of the issue at hand. What *exactly* did you do, what did you expect to happen and what happened instead? Did you encounter any warning or error messages? Please reproduce them *in their entirety* in your question. You can select, copy and paste terminal content and most dialogue messages in Ubuntu. Please **[edit]** your post to add information instead of posting a comment. (see [How do I ask a good question?](/help/how-to-ask)) – David Foerster Aug 14 '18 at 06:23

1 Answers1

2

Edit the system crontab:

sudo vi /etc/crontab

Add the following line to the bottom of the file:

0   23   *   *   *    root     shutdown -h now

Save the file (ZZ in vi). That should run the command "shutdown -h now" every night at 23:00.

user859714
  • 21
  • 2
  • I tried that now but it doesn't work? – Paperboypaddy Aug 14 '18 at 04:31
  • I used this code '0 23 * * * * root shutdown -h now' and it doesn't shutdown when it becomes that time. – Paperboypaddy Aug 14 '18 at 05:06
  • I think there should be one less *. Also, perhaps "root" isn't required. Maybe something like this: 0 23 * * * shutdown -h now . Type "man 5 crontab" to see the format. – Ray Aug 14 '18 at 05:39
  • There are 5 time columns: min, hour, day-of-month, month, day-of week. So Ray is right, it should be "0 23 * * * root shutdown -h now". "root" is needed in /etc/crontab to specify the user running the command. In the user's crontab, no 'user' column is present. I have edited the answer to reflect Ray's correction. – user859714 Aug 16 '18 at 21:31
  • @Paperboypaddy maybe you are missing a newline character at the end of file? According to man, it will cause to cron demon consider the file broken. – user244413 Jul 09 '19 at 19:02