You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux系统如何配置指定时间自动关机?crontab实现方法咨询

Set Up Automatic 10 PM Shutdown on Linux with Crontab

No worries, let's break this down step by step—crontab is perfect for this, and it's straightforward once you know the syntax.

First, understand the crontab time format

Crontab uses a 5-field schedule pattern, in this order:
minute hour day month weekday

  • Minute: 0-59
  • Hour: 0-23 (so 10 PM translates to 22)
  • Day: 1-31
  • Month: 1-12
  • Weekday: 0-7 (0 and 7 both mean Sunday)

An asterisk * means "every" for that field—we'll use this to make the shutdown run every single day.

Step-by-step configuration

  1. Open the crontab editor

    • For your regular user account:
      crontab -e
      
      Note: If you hit permission errors later when the shutdown tries to run, use sudo crontab -e instead to edit the root user's crontab (root has full access to system commands like shutdown).
    • If this is your first time using crontab, it'll ask you to pick an editor. Go with nano—it's the most beginner-friendly option.
  2. Add the shutdown schedule
    Scroll to the bottom of the editor file and paste this line:

    0 22 * * * /sbin/shutdown -h now
    

    Let's unpack this:

    • 0 22: Triggers the command at exactly 22:00 (10 PM)
    • * * *: Runs every day, every month, every weekday
    • /sbin/shutdown -h now: The actual shutdown command (-h means halt; you can swap it for -P to power off the system—they work almost identically on most Linux distros)
  3. Save and exit

    • In nano, press Ctrl+O, hit Enter to confirm the filename, then press Ctrl+X to close the editor.
  4. Verify your setup
    Run this command to check that your new crontab entry was saved correctly:

    crontab -l
    

    You should see the 10 PM shutdown line listed in the output.

Quick extra tips

  • Test before trusting: If you want to confirm the setup works without waiting till 10 PM, add a temporary test line (like triggering a shutdown 1 minute from now):
    * * * * * /sbin/shutdown -h +1
    
    Don't forget to delete this line after testing!
  • Cancel a pending shutdown: If you need to abort a scheduled shutdown before it runs, use:
    shutdown -c
    

内容的提问来源于stack exchange,提问作者user869304

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:52:59