#!/bin/sh
if [[ $EUID -ne 0 ]]; then
echo "请执行su root 再填写密码:xxxxxx" 1>&2
exit 1
fi
echo "======== start clean docker containers logs ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
echo "clean logs : $log"
cat /dev/null > $log
done
echo "======== end clean docker containers logs ========"
运行结果
若需要还可加入到crontab中定时执行,这里就省略了。