nohup日志过大定时清除

Linux评论1,339阅读模式
摘要

nohup日志过大清除脚本,定时执行。

可以将清除功能写成脚本定时执行

#!/bin/bash
# clean the nohup.out of geth-->boot1-->ethRunning.log file of domain
# date:2019-08-19
path="/home/user_dev/wanghaoyi/privateEthereum/boot1"

if [ $# -eq 0  ];then 
    cd $path
    file_size=`du -sm ethRunning.log| awk '{print $1}'`
 
    if [ $file_size -ge 200 ];then
        /bin/cp /dev/null ethRunning.log
        echo "$(date +%F' '%X) :The file size $file_size M , clean it over!" >> $path/clean_nohup.out.log
    else
        echo "$(date +%F' '%X) :The file size $file_size M , not clean it !" >> $path/clean_nohup.out.log
    fi
 
else
    echo "Don't take parameters !"
fi

定时任务

crontab -e

然后输入

30 23 * * * ClearNohup.sh

Linux最后更新:2020-11-6