Automate Dedicated Server Tasks

October 2015

SysAdmin Tips

Did you know that there are many dedicated server tasks that you can automate? Server administrators have so many functions to perform, so it’s important to work efficiently and allow some tasks to essentially complete themselves.

Dedicated hosting tasks such as creating backup files, adjusting multiple server settings, or scanning for viruses can be tedious but are necessary to keep your servers running like clockwork. Automating repetitive tasks is a great way to ensure your time is dedicated to important work. Keep reading to find out which server tasks you can easily automate to reduce your workload and increase overall efficiency.

Why Automate Server Tasks?

Consider how much time it takes to do the following every day: run system updates, perform virus scans, run backups, and complete a routine reboot of your server. Some of your daily tasks don’t take much time but add up once you have to repeat them over and over. Other tasks are more tedious. After waiting for each task to complete, you likely have used up 20 minutes of your day. That’s a lot of hours a month on critical, but pretty boring server tasks.

Now imagine you cut this down to just 30 minutes a month by automating all of these tasks, and spot checking them as necessary. System administrators will be able to apply their expertise where it counts.

Automate System Updates

Automating System Updates on CentOS 6 and 7

 Step 1 – Install yum-cron

yum -y install yum-cron

Step 2 – Edit the settings to your preferences

/etc/sysconfig/yum-cron

Automating System Updates on Debian

Step 1 – Run the following command as root:

apt-get install unattended-upgrades apt-listchanges

Step 2 – Review the default configuration file at /etc/apt/apt.conf.d/50unattended-upgrades and make changes as required.

Step 3 – To activate unattended-upgrades, you need to ensure that the apt configuration stub /etc/apt/apt.conf.d/20auto-upgrades contain the following lines:

editor /etc/apt/apt.conf.d/20auto-upgrades

APT::Periodic::Update-Package-Lists “1”; APT::Periodic::Unattended-Upgrade “1”;

The file /etc/apt/apt.conf.d/20auto-upgrades can be created manually or by running the following command as root:

dpkg-reconfigure -plow unattended-upgrades

These scripts will run a nightly update of all system packages for you.  Please Note: Make sure to keep an eye on your root email for instances when the server is unable to update a script on its own.

Automate Backups

We all know how important it is to maintain system backups. Automating this aspect of your server setup is a great way to ensure you always have a backup when you need it. We have a great article on automating FTP backups on windows as well as automating FTP backups on Linux on our knowledge base.

Automate malware and virus scans

Equally import to backups is maintaining a system free of viruses and malware. You can easily automate ClamAV virus scans. Here’s how to automate virus scans on any Linux distribution:

Step 1 – Install, start, and update ClamAV

On CentOS:
yum install clamav clamav-db clamd

On Debian:
apt-get install clamav clamav-daemon clamav-freshclam

/etc/init.d/clamd start
/usr/bin/freshclam

Step 2 – Setup the daily cron

vi /etc/cron.daily/clamscan_daily

Paste the following:

#!/bin/bash
# email subject
SUBJECT=”VIRUS DETECTED ON `hostname`!!!”
# Email To ?
EMAIL=”me@domain.com”
# Log location
LOG=/var/log/clamav/scan.log

check_scan () {

# Check the last set of results. If there are any “Infected” counts that aren’t zero, we have a problem.
if [ `tail -n 12 ${LOG} | grep Infected | grep -v 0 | wc -l` != 0 ]
then
EMAILMESSAGE=`mktemp /tmp/virus-alert.XXXXX`
echo “To: ${EMAIL}” >> ${EMAILMESSAGE}
echo “From: alert@domain.com” >> ${EMAILMESSAGE}
echo “Subject: ${SUBJECT}” >> ${EMAILMESSAGE}
echo “Importance: High” >> ${EMAILMESSAGE}
echo “X-Priority: 1” >> ${EMAILMESSAGE}
echo “`tail -n 50 ${LOG}`” >> ${EMAILMESSAGE}
sendmail -t < ${EMAILMESSAGE}
fi

}

clamscan -r / –exclude-dir=/sys/ –quiet –infected –log=${LOG}

check_scan

chmod +x /etc/cron.daily/clamscan_daily

This script will run a daily malware scan, and email you about any infected files.

Automate routine server tasks with the ReliableSite API

Do you need to routinely reboot a server, or generate a report of all the servers in your portfolio? The ReliableSite API is a great tool for automating many of these tasks. You can program a server to reboot via the API at specific intervals, or generate a list of all of the hard drives available across your fleet of servers.

Have any questions about the ReliableSite API or automating dedicated host tasks? Please contact our support team!