#!/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
转载于:https://blog.51cto.com/13958766/2295919