RE: Automatic weekly updates and reboot server if needed Ubuntu
12-18-2015, 07:49 AM
(This post was last modified: 02-03-2016, 12:42 PM by pinguy.)
Full disclosure. My update script is slightly different as I also clean out logs.
This is what mine looks like:
But it really isn't advised to delete the logs. I have a system that backs up the logs once a week then deletes them.
I did this because my server stopped working after about 18 Months because my log files were over 6GBs (I only had a 20GB drive).
My setup is fully automated. I never have to look after it. I am happy with my setup because it is for me. But I would never do this setup for a client. So use this with your own discretion.
This is what mine looks like:
Code:
#!/bin/bash
/usr/bin/dpkg --configure -a
/usr/bin/apt-get update
/usr/bin/apt-get -qy dist-upgrade
/usr/bin/apt-get install -f
/usr/bin/apt-get clean
/usr/bin/apt-get -qy autoremove
Logs
rm -rf /var/sentora/hostdata/zadmin/logs.zip
cd /var/
zip -r /var/sentora/hostdata/zadmin/logs.zip log
dropbox_uploader delete /logs.zip
dropbox_uploader upload /var/sentora/hostdata/zadmin/logs.zip /logs.zip
Logs
find /var/log -type f -delete
touch /var/log/dovecot.log
touch /var/log/dovecot-info.log
touch /var/log/dovecot-debug.log
chown vmail.mail /var/log/dovecot*
service dovecot restart
if [ -f /var/run/reboot-required ]; then
sudo touch /forcefsck
sudo reboot
else
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
exit 0
fi
But it really isn't advised to delete the logs. I have a system that backs up the logs once a week then deletes them.
I did this because my server stopped working after about 18 Months because my log files were over 6GBs (I only had a 20GB drive).
My setup is fully automated. I never have to look after it. I am happy with my setup because it is for me. But I would never do this setup for a client. So use this with your own discretion.