Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of excessive output of nohup log under linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

The purpose of this article is to share with you how to solve the problem of excessive nohup log output under linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. The nohup command explains:

A, syntax: nohup [command] [args] [&]

B, description: the nohup command runs the command specified by the Command parameter and any related Arg parameters, ignoring all hang-up signals. Use the nohup command to run the program in the background after logging out. To run the nohup command in the background, add & (the symbol for "and") to the end of the command. If no redirection is specified, the log is output to the nohup.out file under the current directory by default.

Generally submit such as: nohup. / execute.sh & such log or output in .nohup.out

Redirect: nohup. / execute.sh > / home/xxx/log.log 2 > & 1 &: then the log will be redirected to the specified directory

2. Syncopate nohup.out without allowing it to grow indefinitely

The general submission command I use here: nohup. / execute.sh &, so that there are nohup.out files in the current directory. At this time, you can find a way to regularly split the nohup.out into multiple small files, but at the same time make sure that the nohup.out does not grow indefinitely (in general, the program cannot be interrupted):

A. Every day (set time as needed), regularly split the log of the previous day (for example, about 1g per day, so can you split about 100m at a time)

B. After slicing the nohup.out file, ensure that the new output log will continue to be output to nohup.out.

The above is in shell

Current_date= `date-d "- 1 day"+% Y%m%d" `

Split-b 65535000-d-a 4 nohup.out. / log/log_$ {current_date} _ here use the split command to split the nouhup file according to the specified size (65535000b is about more than 60 M, you can customize the size), and divide it into the specified format (- d-a 4 is suffixed with a 4-digit suffix starting from 0000, you can use the Baidu split command). The final output format is log_20160610_0001.

Cat / dev/null > nohup.out (this command will instantly empty the nohup.out file and continue to write it later) to direct the log to / dev/null

You can do the same with redirected output, except that you can change it to the redirected file name

Define these commands as a shell file that runs regularly every day, so that the daily log is divided into several parts, which is convenient for troubleshooting, and if the log backlog is too large. You can delete historical logs regularly and keep them in recent days.

The overall code is as follows:

This_path=$ (cd `date $0`; pwd) cd $this_pathecho $this_pathcurrent_date= `date-d "- 1 day" +% Y%m%d "`echo $current_datesplit-b 65535000-d-a 4 / home/.../nohup.out / home/.../log/log_$ {current_date} _ cat / dev/null > nohup.out Thank you for reading! This is the end of this article on "how to solve the problem of excessive output of nohup logs under linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report