About Nohup.out logs in Linux is too big a problem

Source: Internet
Author: User



About Nohup.out logs in Linux is too big a problem






Background, Java project, generally run Java program need to use the Nohup command to implement the background boot log, the default is saved in the current Nohup.out file. However, some programs output nohup files that are too large to happen.






Here are the solutions:



1, Create a clearnohup.sh script in the directory where the Nohup.out is located, and let it clean up once a week through timed tasks. Prevent nohup files from being too large.


#!/bin/bash
#
this_path=$(cd `dirname $0`;pwd) #According to the path of the script
cd $this_path
echo $this_path
current_date=`date -d "-1 day" "+%Y%m%d"` #List the time
echo $current_date
split -b 60m -d -a 4 ./nohup.out ./logs/nohup-${current_date} #Split each block of 60 megabytes into the logs file, the format is: nohup-xxxxxxxxxx
cat /dev/null> nohup.out#Clear the nohup.out file in the current directory


2. Add a scheduled task



Crontab-e





* * * * * */1/cljj/apps/21.biz_channel/clearnohup.sh #每周执行清理日志操作





Note:



1. Nohup Command Explanation:



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



B. Description: The nohup command runs commands specified by the command parameter and any related ARG parameters, ignoring all hang-up signals. Use the Nohup command to run a program in the background after logging off.  To run the Nohup command in the background, add & (the symbol for "and") to the end of the command, and if you do not specify a redirect, the log is output to the current directory in the Nohup.out file, typically submitted as: Nohup./execute.sh & So the log or output is currently running under. Nohup.out Redirect: Nohup./execute.sh >/home/xxx/log.log 2>&1 &: This will redirect the log to the specified directory



2. Split command can divide a large file into many small files, sometimes need to split the file into smaller fragments, such as to improve readability, generate logs and so on.



Options



-B: The value is the size of each output file, in bytes.



-C: The maximum number of bytes for a single line in each output file.



-D: Use a number as a suffix. You can also use-a length to specify the length of the suffix:



-L: The value is the size of the number of columns per output file.



For example:



Generate a 100k file and split (format datafile201703230000).


# dd if=/dev/zero bs=100k count=1 of=date.file
# split -b 10k -d -a 4 ./date.file   ./logs/nohup$(date +\%Y\%m\%d)log
# cd logs/ ;ls
nohup20170323log0002  nohup20170323log0006  
nohup20170323log0003  nohup20170323log0007  
nohup20170323log0000  nohup20170323log0004 
nohup20170323log0001  nohup20170323log0005





This article is from the "Ljohn" blog, make sure to keep this source http://ljohn.blog.51cto.com/11932290/1909665



About Nohup.out logs in Linux is too big a problem


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.