处理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命令生成的大文件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

数据挖掘

数据挖掘

(美)Jiawei Han、(加)Micheline Kamber、(加)Jian Pei / 范明、孟小峰 / 机械工业出版社 / 2012-8 / 79.00元

数据挖掘领域最具里程碑意义的经典著作 完整全面阐述该领域的重要知识和技术创新 这是一本数据挖掘和知识发现的优秀教材,结构合理、条理清晰。本书既保留了相当篇幅讲述数据挖掘的基本概念和方法,又增加了若干章节介绍数据挖掘领域最新的技术和发展,因此既适合初学者学习又适合专业人员和实践者参考。本书视角广阔、资料翔实、内容全面,能够为有意深入研究相关技术的读者提供足够的参考和支持。总之, 强烈推荐......一起来看看 《数据挖掘》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

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

在线 XML 格式化压缩工具