Skip to content

Instantly share code, notes, and snippets.

@delano
Forked from jdowning/ami-clean.sh
Last active October 26, 2022 23:26
Show Gist options
  • Select an option

  • Save delano/4eee6bcfce0b6e3c83f1e98d9cd7af16 to your computer and use it in GitHub Desktop.

Select an option

Save delano/4eee6bcfce0b6e3c83f1e98d9cd7af16 to your computer and use it in GitHub Desktop.

Revisions

  1. delano revised this gist Oct 26, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    See: https://gist.github.com/delano/4eee6bcfce0b6e3c83f1e98d9cd7af16

  2. delano revised this gist Oct 26, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ami-clean.sh
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,8 @@ function print_green {

    print_green 'Clean Apt'
    apt-get -y autoremove
    aptitude clean
    aptitude autoclean
    apt clean
    apt autoclean

    print_green 'Remove SSH keys'
    [ -f /home/ubuntu/.ssh/authorized_keys ] && rm /home/ubuntu/.ssh/authorized_keys
  3. delano revised this gist Oct 26, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions ami-clean.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    #!/bin/bash

    # Forked from: https://gist.github.com/justindowning/5921369/raw/ami-clean.sh

    # This script cleans up your EC2 instance before baking a new AMI.
    # Run the following command in a root shell:
    #
    # bash <(curl -s https://gist.github.com/justindowning/5921369/raw/ami-clean.sh)
    # bash <(curl -s https://gist.githubusercontent.com/delano/4eee6bcfce0b6e3c83f1e98d9cd7af16/raw/ami-clean.sh)

    function print_green {
    echo -e "\e[32m${1}\e[0m"
    @@ -25,4 +27,4 @@ unset HISTFILE
    [ -f /root/.bash_history ] && rm /root/.bash_history
    [ -f /home/ubuntu/.bash_history ] && rm /home/ubuntu/.bash_history

    print_green 'AMI cleanup complete!'
    print_green 'AMI cleanup complete!'
  4. @jdowning jdowning revised this gist Jul 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ami-clean.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # This script cleans up your EC2 instance before baking a new AMI.
    # Run the following command in a root shell:
    #
    # bash <(curl -s https://gist.github.com/justindowning/ami-clean.sh)
    # bash <(curl -s https://gist.github.com/justindowning/5921369/raw/ami-clean.sh)

    function print_green {
    echo -e "\e[32m${1}\e[0m"
  5. @jdowning jdowning created this gist Jul 3, 2013.
    28 changes: 28 additions & 0 deletions ami-clean.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash

    # This script cleans up your EC2 instance before baking a new AMI.
    # Run the following command in a root shell:
    #
    # bash <(curl -s https://gist.github.com/justindowning/ami-clean.sh)

    function print_green {
    echo -e "\e[32m${1}\e[0m"
    }

    print_green 'Clean Apt'
    apt-get -y autoremove
    aptitude clean
    aptitude autoclean

    print_green 'Remove SSH keys'
    [ -f /home/ubuntu/.ssh/authorized_keys ] && rm /home/ubuntu/.ssh/authorized_keys

    print_green 'Cleanup log files'
    find /var/log -type f | while read f; do echo -ne '' > $f; done

    print_green 'Cleanup bash history'
    unset HISTFILE
    [ -f /root/.bash_history ] && rm /root/.bash_history
    [ -f /home/ubuntu/.bash_history ] && rm /home/ubuntu/.bash_history

    print_green 'AMI cleanup complete!'