Systems - Ubuntu - Clean Up

Bash shell script to clean up Ubuntu.

#!/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