Auto Update Script for Linux

Submitted by brett.ferringer on Tue, 10/05/2021 - 23:13

 This script is meant to automate my Linux server update process. It logs the results to my Maria DB database.

 

#!/bin/bash
dun='<username>'
dpw='<password>'
dip='<ipaddress>'
dn='logs'
serverName='<servername>'
mysql --host=$dip --user=$dun --password=$dpw $dn -e "UPDATE processes SET tmp = '' WHERE tmp = 'sSM$serverName'"
mysql --host=$dip --user=$dun --password=$dpw $dn -e "INSERT INTO processes (name, status, start, tmp, server) VALUES ('systemMaintenance', 'start', now(), 'sSM$serverName', '$serverName')"
apt-get update
apt-get -y upgrade
apt-get -y autoremove
apt-get autoclean
mysql --host=$dip --user=$dun --password=$dpw $dn -e "UPDATE processes SET end = now(), tmp = '', status = 'finished' WHERE tmp = 'sSM$serverName'"