Last active
December 6, 2021 08:03
-
-
Save gacyun/e7117e5a3b10553b49be28c719abb372 to your computer and use it in GitHub Desktop.
Revisions
-
gacyun revised this gist
Dec 6, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,8 @@ #!/bin/bash # Run this script with: # bash <(curl -L -s https://gist.github.com/gacyun/e7117e5a3b10553b49be28c719abb372/raw/aws-ami-clean.sh) function print_green { echo -e "\e[32m${1}\e[0m" } -
gacyun created this gist
Dec 6, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/bin/bash function print_green { echo -e "\e[32m${1}\e[0m" } function clean_package_cache { which yum && { yum clean all return } which apt-get && { apt-get -y autoremove aptitude clean aptitude autoclean return } } print_green 'clean yum cache' clean_package_cache print_green 'remove ssh keys' [ -f /home/ec2-user/.ssh/authorized_keys ] && rm /home/ec2-user/.ssh/authorized_keys print_green 'clean logs' find /var/log -type f | while read f; do echo -ne '' > $f; done print_green 'clean bash history' unset HISTFILE [ -f /root/.bash_history ] && rm /root/.bash_history [ -f /home/ec2-user/.bash_history ] && rm /home/ec2-user/.bash_history print_green 'ami clean finished!'