Clean Ubuntu 14x or 16x for Proxmox VE Template

Bash shell script to clean up Ubuntu for Proxmox VE Template

#!/bin/bash
# Stop rsyslog to clean up logs
service rsyslog stop

# Cleanup all logs
cat /dev/null > /var/log/audit/audit.log
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/lastlog

#cleanup persistent udev rules
rm /etc/udev/rules.d/70-persistent-net.rules

#cleanup /tmp directories
rm -rf /tmp/*
rm -rf /var/tmp/*

#cleanup current ssh keys
rm -f /etc/ssh/ssh_host_*
sed -i -e 's|exit 0||' /etc/rc.local
sed -i -e 's|.*test -f /etc/ssh/ssh_host_dsa_key.*||' /etc/rc.local
bash -c 'echo "test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server" >> /etc/rc.local'
bash -c 'echo "exit 0" >> /etc/rc.local'

# Clear hostname
cat /dev/null > /etc/hostname

# Cleanup apt
apt-get clean

#cleanup shell history
history -w
history -c