Linux設(shè)置定時(shí)重啟
Linux設(shè)置定時(shí)重啟
藍(lán)隊(duì)云小課堂:
使用 systemd 設(shè)置定時(shí)重啟
使用 root 用戶登錄終端。
創(chuàng)建一個(gè)新的 systemd 服務(wù),例如 reboot.service。
sudo touch /etc/systemd/system/reboot.service
使用文本編輯器(例如vi)打開該文件,并輸入以下內(nèi)容:
[Unit]
Description=Reboot Service
[Service]
Type=oneshot
ExecStart=/sbin/reboot
[Install]
WantedBy=multi-user.target
保存并關(guān)閉文件。
創(chuàng)建一個(gè)新的 systemd 定時(shí)器,例如 reboot.timer。
sudo touch /etc/systemd/system/reboot.timer
使用文本編輯器打開該文件,并輸入以下內(nèi)容:
[Unit]
Description=Reboot Timer
[Timer]
OnCalendar=*-*-* 02:30:00
[Install]
WantedBy=timers.target
sudo systemctl enable --now reboot.timer
這樣就可以在每天早上 2:30 重啟了。
使用 cron 設(shè)置定時(shí)重啟
使用 root 用戶登錄終端。
打開 cron 配置文件:
crontab -e
在文件末尾加入下面一行,表示每天凌晨 2:30 重啟:
30 2 * * * /sbin/reboot
更多小知識(shí),可聯(lián)系藍(lán)隊(duì)云一起探討。
會(huì)員登錄
賬號(hào)登錄還沒有賬號(hào)?立即注冊