首页 > 系统服务 > 详细

shell脚本定时清除messages日志及TAG为none的docker images

时间:2018-10-08 16:33:33      阅读:214      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
logstatus=du -sh /var/log/messages
docker_image=docker images
docker_none=docker images|grep none
docker_rm=docker images|grep none|awk ‘{print $3 }‘
disk=df -h
cleanlog()
{
echo "######start clean messages#######"
echo "目前日志大小 $logstatus"
read -p "是否清理messages日志,请输入(yes/no): " messlog
if [ ${messlog} = "yes" ];then
cat /dev/null > /var/log/messages
logstatus=du -sh /var/log/messages
echo -e "清理后 $logstatus"

if [ ${messlog} = "no" ];then
    exit 0
fi

fi
return 0
}
cleandockerimage()
{
echo "######start clean docker image#######"
if [ -n "${docker_rm}" ];then
echo -e "删除以下TAG为"none"的doncker images\n$docker_none"
else
echo -e "==============================================================================\n无TAG为none的docker image\n已退出当前脚本"
exit 0
fi

read -p "是否继续删除,请输入(yes/no) " delimage
if [ ${delimage} = "yes" ];then
for i in ${docker_rm}
do
docker rmi -f ${i}
echo "=============================================================================="
echo -e "删除成功:docker images列表 \n$docker_image"
done
if [ ${delimage} = "no" ];then
exit 0
fi
fi
return 0
}

echo -e "目前磁盘状态\n==============================================================================\n$disk"
echo -e "\n==============================================================================\n磁盘垃圾清理"
echo -e "1.清理系统日志\n2.清理Docker镜像\n3.Clean All !!!"
read -p "请按序号输入选择后续操作 : " choose

if [ $choose -eq 1 ];then
sleep 1;
echo "=============================================================================="
cleanlog
fi
if [ $choose -eq 2 ];then
sleep 1;
echo "=============================================================================="
cleandockerimage
fi
if [ $choose -eq 3 ];then
cleanlog
cleandockerimage
fi

shell脚本定时清除messages日志及TAG为none的docker images

原文:http://blog.51cto.com/13958766/2295919

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!