处理nohup命令生成的大文件

栏目: Go · 发布时间: 7年前

内容简介:工作的时候,用到了Golang开发项目,将Golang打包(go build)生成执行文件,之后用nohup命令运行假设下面两句是先把

工作的时候,用到了Golang开发项目,将Golang打包(go build)生成执行文件,之后用nohup命令运行

nohup ./gopack &

假设 gopack 是生成的执行文件,上面的命令执行后,要在当前目录下生成一个 nohup.out 文件,在不停下进程的情况下, nohup.out 文件会越来越大,于是就打算对它切分另存并清空。

#!/bin/bash
thepath=/data/testshell

if [ ! -d "$thepath/log/" ];then
mkdir $thepath/log
fi

chmod -R 777 $thepath/log


if [ -f "$thepath/nohup.out" ];then

cpDate=`date -d "-1 day" "+%Y%m%d"`
cp $thepath/nohup.out $thepath/log/log_${cpDate}.log
cat /dev/null > $thepath/nohup.out
split -b 512 -d -a 4 $thepath/log/log_${cpDate}.log $thepath/log/log_${cpDate}_
rm -fr $thepath/log/log_${cpDate}.log

fi

下面两句是先把 nohup.out 复制,然后清空:

cp $thepath/nohup.out $thepath/log/log_${cpDate}.log
cat /dev/null > $thepath/nohup.out

split 命令对另存的文件切分

split -b 512 -d -a 4 $thepath/log/log_${cpDate}.log $thepath/log/log_${cpDate}_

最后删除另存的文件:

rm -fr $thepath/log/log_${cpDate}.log

以上所述就是小编给大家介绍的《处理nohup命令生成的大文件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Producing Masculinity

Producing Masculinity

Michele White / Routledge / 2019-3 / $39.95

Thoughtful, witty, and illuminating, in this book Michele White explores the ways normative masculinity is associated with computers and the Internet and is a commonly enacted online gender practice. ......一起来看看 《Producing Masculinity》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具