Summary: Set Linux devices to restart or shut down periodically
Problem: A person who always needs to use a device on a daily basis to manually reboot to work properly, but check the log, it seems that the service is normal. The time and the correct time differ by 4mins.
Workaround:
1. Increase the scheduled task, set the automatic restart;
2. Modify the correct time, and increase the automatic synchronization;
Are relatively simple commands, here a simple record, can be for the needs of the students reference;
To increase the scheduled task, set the automatic restart:
Edit crontab:
sudo crontab-e
Add timed restart command to view crontab
[Email protected]:~ $ sudo crontab-l
# Edit This file to introduce the tasks to is run by Cron.
#
# each task to run have to is defined through a single line
# indicating with different fields when the task would 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 the Week (Dow) or use ' * ' in these fields (for ' any '). #
# Notice that tasks would 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 of 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 * * * sudo-u root reboot
Restart the service to ensure that it takes effect:
sudo service cron restart
sudo vi/etc/sudoers
Other:
Crontab that require root permission to perform, such as shutdown shutdown required: sudo crontab-e
In the editor, add the following 2 lines, the time is recorded in the log, 22 30 minutes a day to perform the shutdown command, 1 minutes warning will automatically shut down
* * * Date >>/home/haochuang/temp/shutdown.log30 * * * sudo-u root shutdown-h 1
</END>
"Raspberry Pi" crontab set Linux device timed restart