美文网首页
python3清空nohup.out文件

python3清空nohup.out文件

作者: 小黑佬 | 来源:发表于2020-04-01 15:32 被阅读0次

purge_nohup_out.py

import os
import logging
import psutil


logging.basicConfig(
        filename='app.log',
        level=logging.INFO,
        format='%(levelname)s:%(asctime)s:%(message)s'
    )


def purge_nohup() :
    for root, dirs, files in os.walk('/home/centos', topdown=False):
        for name in files:
            # print(name)
            # 判断是否包含nohup
            if "out" in name and "nohup" in name:
                print(os.path.join(root, name))
                with open(os.path.join(root, name),'w') as f:
                    print(os.stat(os.path.join(root, name)).st_size)
                    print(os.path.getsize(os.path.join(root, name)))
                    logging.info('the file   %s is null ', os.path.join(root, name))


disk_usage=psutil.disk_usage('/')
print("硬盘根目录使用率为%s" % disk_usage.percent)
disk_usage=int(disk_usage.percent)
print("硬盘根目录使用率为%s" % disk_usage)
if disk_usage > 5:
    purge_nohup()



相关文章

网友评论

      本文标题:python3清空nohup.out文件

      本文链接:https://www.haomeiwen.com/subject/jdlauhtx.html