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 * * * /home/user_dev/wanghaoyi/privateEthereum/ClearNohup.sh

(每晚23:30定时执行任务,若超过200M则清除)

 

你可能感兴趣的:(nohup日志过大定时清除)