The daily rsync (file server backup) I've been running on CentOS lately sometimes fails ... (´ ・ ω ・ `)
I don't know the cause yet, but I decided to restart it every day for the time being.
this.
python
shutdown -r now
-r
Is the "restart" option.
-h
Note that is an option to "turn off the power".
(If you turn off the power, you have to go to the front of the machine and click the power button)
First, edit the cron configuration file with vi with the following command.
python
crontab -e
Added the following contents.
python
0 3 * * * /usr/sbin/shutdown -r now
Minute, hour, day, month, day of the week command
In the above case, run "/ usr/sbin/shutdown" at 3:00 every day! The option is "-r now"! Meaning.
This is to avoid the exception of "command not found" in cron.
Some commands ** can be executed on a terminal but not with cron **. (The reason is that the path does not pass when executing with cron)
So, I added ```/usr/sbin /` `` to make it ** a command specified with an absolute path ** instead of just a command.
If you want to know the absolute path of shutdown, use the following command.
python
which shutdown
You can easily check it with the following command.
python
last reboot
The result looks like this. It restarted at 4:51 on Friday, January 1, meaning that it has been working since then.
It will restart at 3:00 or in the middle of the night, so let's know how to check it later.
For example, the following is a command to start Samba (file server service) at the same time.
python
systemctl enable smb
At first, I tried to execute it regularly with this ↓. ~~ I want to specify the date, day of the week, and time on CentOS and execute it regularly ~~
systemctl enable restart service
Because I've done that
Scheduled restart ⇒ ** Restart service starts at the same time as CentOS starts ** ⇒Restart ⇒ ** Restart service starts at the same time as CentOS starts ** ⇒Restart ⇒ ………
It has become an infinite loop ☆ (・ ω <)
If you set `` `-k``` in the shutdown option, you can ** notify the connected terminal ** that it will be restarted **. This is used infrequently but convenient.
Hmmm, I thought I could remember that kind of thing.
I wanted to create a mechanism to notify Line at the same time as starting up or skip mail!
When I restart, the network drive on my Mac mini is unmounted ... (´ ・ ω ・ `) (Tico = file server built with Samba on CentOS) It seems necessary to set a regular execution script on the Mac side or set it so that it will not be unmounted. Well, this is a remaining task.
https://eng-entrance.com/linux-command-shutdown https://rainbow-engine.com/linux-scheduled-reboot-script/ https://teratail.com/questions/75302 https://gist.github.com/koudaiii/49ac3f8b7c207f0da31f https://netacore.jp/restart-automatically-centos-server/
CentOS Linux release 8.3.2011
Recommended Posts