0 0 * * * python /home/disk.py > /dev/null 2>&1
#!/bin/bash
# 定义日志文件路径
LOG_FILE="/var/lib/docker/containers/e09b9f801d9dc1b17fbb058be78c31cd79d66c1349b10dc41c52d3145be6ab10/e09b9f801d9dc1b17fbb058be78c31cd79d66c1349b10dc41c52d3145be6ab10-json.log"
# 判断日志文件是否存在
if [ -f "$LOG_FILE" ]; then
# 获取日志文件大小(以字节为单位)
FILE_SIZE=$(stat -c%s "$LOG_FILE")
# 将10GB转换为字节(1GB = 1073741824字节)
TEN_GB=$((10 * 1073741824))
# 判断文件大小是否超过10GB
if [ "$FILE_SIZE" -gt "$TEN_GB" ]; then
# 清空日志文件
echo ' ' > "$LOG_FILE"
echo "日志文件已清空。"
else
echo "日志文件大小未超过10GB,无需清空。"
fi
else
echo "日志文件不存在。"
fi
#!/usr/bin/python env
import os
#file_path = "/var/lib/docker/containers/9182da9c8bb29a8e437516bdfa56930bf51eec583ab3ea4b75eb024482f8eb92/9182da9c8bb29a8e437516bdfa56930bf51eec583ab3ea4b75eb024482f8eb92-json.log"
file_path = "/var/lib/docker/containers/e09b9f801d9dc1b17fbb058be78c31cd79d66c1349b10dc41c52d3145be6ab10/e09b9f801d9dc1b17fbb058be78c31cd79d66c1349b10dc41c52d3145be6ab10-json.log"
if os.path.isfile(file_path):
file_size = os.path.getsize(file_path)
if file_size > 1 * 1024 * 1024 * 1024:
with open(file_path, "a") as f:
f.seek(0)
f.truncate()
else:
print("The file does not exist.")