Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure scheduled restart for Linux

Shulou Source: shulou.com Published: 2022-06-01 15:20:05 09月18日 Update

This article mainly explains "how to configure timed restart in Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to configure timed restart in Linux.

1. Create a new .sh file in the service directory

Cd / opt/tsp/

Touch restart.sh

\ 2. View

3. Edit restart.sh script

Jps-l | grep wx | awk'{print $1}'| xargs kill-9 nohup java-jar / opt/tsp/wx.jar > / opt/tsp/wx.out 2 > & 1 &

4. Explain the meaning of the script

Jps-l | grep wx (ps-ef | grep wx) query the process of wx.jar

Awk'{print $1} 'gets the first column of the process query result structure

| | xargs kill-9 kill drops the process number queried |

Nohup java-jar / opt/tsp/wx.jar > / opt/tsp/wx.out 2 > & 1 & start command

5. Write scheduled tasks, enter the editor, press the I button, and you can enter it.

\ 6. Explain the command 40 15 * * 5 sh / opt/tsp/restart.sh execute the restart.sh script at 15:40 on Friday

Write rules:

The first five bits are timed and the time period is described as follows:

The first * indicates minutes: value range: 0-59

The second * indicates the hour: value range: 0-23

The third * indicates the number of days: value range: 1-31

The fourth * indicates the month: value range 1-12

The fifth * indicates weekly: value range: 0-6

"*" represents a number in the range of values, "/" represents "every", "-" represents from a certain number to a certain number, "," separates several discrete numbers.

7. Cron service

/ sbin/service crond start/sbin/service crond stop/sbin/service crond restart/sbin/service crond reload/sbin/service crond status Thank you for your reading. The above is the content of "how to configure scheduled restart of Linux". After the study of this article, I believe you have a deeper understanding of how to configure scheduled restart of Linux, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Scope configuration numbers representatives processes learning queries content commands scripts services interpretation three tasks cycles days hours that is ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Huawei Apple vpn