Shut Down My Server At Secific Time

hi everyone , i want to setup a command or something that automatically shuts down my server at a specific time and start at specific time daily ?

please suggest

Could you explain more details, like what OS, etc.

1 Like

i am ubuntu server 22.04

1. Setting Up Automatic Shutdown with Crontab:

  • Accessing the Terminal: Whether you’re SSH’ing into your server or using the terminal directly, start here.
  • Editing the Crontab File:
    • Type crontab -e to edit the cron jobs.
    • Choose an editor you’re comfortable with, like Nano or Vim.
  • Adding the Shutdown Command:
    • The crontab format follows: minute, hour, day, month, weekday, command.
    • To shut down daily at 10 PM, add: 0 22 * * * /sbin/shutdown -h now.
    • Save your changes and exit the editor.

2. Setting Up Automatic Startup:

  • This part varies significantly between BIOS and UEFI systems. Here’s a general overview for both:

For BIOS Systems:

  • Accessing BIOS Settings:
    • Restart your server and press the key to enter BIOS (often F2, F10, DEL, or ESC).
  • Finding the Power Options:
    • Look for “Power Management” or similar settings.
    • Enable the “Resume by Alarm” or equivalent feature.
  • Setting the Startup Time:
    • Choose the time for the server to automatically start.

For UEFI Systems:

  • Entering UEFI Settings:
    • Similar to BIOS, but the interface and options might be more user-friendly.
  • Locating Startup Options:
    • Look for “Boot Options” or “Power Management” settings.
    • Find the feature that allows scheduling startup times.
  • Configuring Startup Time:
    • Set your desired startup time.
  • In both cases, save your settings before exiting.

3. Additional Tips:

  • BIOS vs UEFI Distinction: The steps can vary a lot. If you’re unsure, check your server’s documentation for specific instructions.
  • Using Crontab for Startup: Contrary to popular belief, crontab cannot directly schedule a server startup as it can with a shutdown. This is because crontab entries run only when the system is up. For startup, you’ll need to rely on BIOS/UEFI settings or external tools.

4. Further Resources:

  • Since procedures can differ based on server models, it’s beneficial to refer to specific manuals or online resources tailored to your server’s make and model.

By incorporating these steps, you should be able to set up automatic shutdown and startup times for your Ubuntu server.

1 Like

damn i was using shutdown wrong way lol

shut down dint worked with this command :frowning: server is still running

sudo /usr/sbin/shutdown -h now

this command works fine if i run it outside cron , dnt know why cron isnt working