Last active
January 24, 2019 17:37
-
-
Save ratulbasak/4294c8f5a70e659a8c48bc6b080cb561 to your computer and use it in GitHub Desktop.
if disk space is greater than 80% then Remove all docker images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export docker_server=https://AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com | |
export token=$(aws ecr get-authorization-token --query authorizationData[].authorizationToken --output text | base64 -d | cut -d: -f2) | |
#export login=`echo $aws_login` | |
#$login | |
docker login -u AWS -p $token $docker_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
volume='/dev/xvda1' | |
space=$(df -H $volume | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 }') | |
cmd=$(df -H $volume | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 }' | cut -d'%' -f1) | |
if [ $cmd -ge 80 ]; then | |
echo "Running out of space. Deleting docker images" | |
docker rm $(docker ps -a -q) | |
docker rmi $(docker images -aq) | |
else | |
echo "Diskspace is available $volume : $space" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment