长时间运行树莓派发现会莫名卡顿,于是这里打算使用 crontab 计划任务定时重启树莓派看下是否可行。
确认 shutdown 命令位置
root@raspberrypi:~# whereis shutdown
shutdown: /usr/sbin/shutdown /usr/share/man/man2/shutdown.2.gz /usr/share/man/man8/shutdown.8.gz
root@raspberrypi:~#编辑新增计划任务
root@raspberrypi:~# crontab -e
no crontab for root - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.tiny
3. /bin/ed
Choose 1-3 [1]: 2
crontab: installing new crontab
crontab: installing new crontab
root@raspberrypi:~#查看计划任务列表
排除#开头的行,可以看到最后一行新增了一个每天17点40分定时重启的计划任务。
root@raspberrypi:~# crontab -l
# 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
40 17 * * * /usr/sbin/shutdown -r now
root@raspberrypi:~#
本文采用 知识共享署名4.0 国际许可协议进行许可。
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。
如果您的问题未解决,欢迎微信扫描右侧二维码与我联系。