背景简介
设置系统每天自动关机。
前置信息
- Linux
- Crontab
详细信息
第一步: 打开 root 的 crontab 设置
sudo crontab -e
- 如果是第一次加载,按需求选择编译器即可,例如
1
no crontab for root - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/mcedit
3. /usr/bin/vim.tiny
Choose 1-3 [1]:
- 配置自动重启的时间即可
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 0 * * * /sbin/shutdown -h now
参考备注:
m第一个参数为分钟(Minutes)h第二个参数位小时(Hour)dom第三个参数为每月的哪一天(Day of Month)mon第四个参数为月份(Month)dow第五个参数为每星期的哪一天(Day of Week)command第六个参数为需要执行的指令
保存后退出即可
crontab: installing new crontab
以上便是本文的全部内容,感谢您的阅读,如遇到任何问题,欢迎在评论区留言讨论。