1

My question relates to the following question:

Daily server reboot cron?

I want to shutdown my server at 10.15pm and auto restart at 6am.

I added the following line in crontab, but it would just reboot my server at 6am and even that is not working:

15 22 * * * root /sbin/shutdown -r +465

But how should I do it? Is there a better application?

Thanks.

mike_03
  • 11

3 Answers3

2

You can use a cron line like

15 22 * * * root /usr/sbin/rtcwake -m off -s 22440

(22:15 -> 6 = 7h45 = 22440 seconds (if wrong do edit ;)) .

  • shutdown at 22:15
  • 22440 seconds later reboot.

Synopsis

rtcwake [-hvVlua] [-d device] [-m standby_mode] {-t time_t|-s seconds}

Description

This program is used to enter a system sleep state until specified wakeup time.

This uses cross-platform Linux interfaces to enter a system sleep state, and leave it no later than a specified time. It uses any RTC framework driver that supports standard driver model wakeup flags.

This is normally used like the old apmsleep utility, to wake from a suspend state like ACPI S1 (standby) or S3 (suspend-to-RAM). Most platforms can implement those without analogues of BIOS, APM, or ACPI.

On some systems, this can also be used like nvram-wakeup, waking from states like ACPI S4 (suspend to disk). Not all systems have persistent media that are appropriate for such suspend modes.

Rinzwind
  • 299,756
0

Your cron line issues the shutdown command to schedule a reboot 465 minutes later – and that’s exactly what you are experiencing. To shut down the computer immediately in the given time instead, modify the cron line:

15 22 * * * root /sbin/shutdown -h now

You cannot schedule starting the computer (not restarting when it’s been off before) using cron or by any other OS means – simply because OS is not running when the command is supposed to run. However, you can mostly schedule starting the computer in firmware (BIOS) settings. The exact instructions depend on your motherboard’s firmware.

Linux computers usually maintain system clock (used by BIOS, too) in the UTC time, so take it into account when setting the start time in BIOS. Also, don’t forget to think about DST if it’s applied in your location.

Melebius
  • 11,431
  • 9
  • 52
  • 78
0

Thanks Melebius for the input. Shutdown works fine now. I found a solution and a problem I had for startup (Wake on demand, not on time): I use WOL now. (Wake On Lan)

  1. Hardware/BIOS: In the Power section you have to enable the power up funktion from PCI or PCIE (onboard) devices. (Differs in different BIOS) Check the BIOS battery! This was my problem. It was dead and BIOS was set to default after an hour.

  2. Software: I used ethtool with this manual: Setting-up-wol-on-ubuntu-server-18.04

A second solution is a smart-plug. It monitores your energy consumption and you can use an ON/OFF timer. Just enable the wake on power up in BIOS. If the PC gets power, it automatically restart the system.

mike_03
  • 11