Category: Linux

Setup Auto Updating Apt-get Update/Upgrade with Logging

Here’s some quick steps on how to setup automatic apt-get upgrade and apt-get update on your ubuntu server, with the capability of logging and sending someone of your choosing a notification of the updates and what the output was.

I pieced this together from various sources around the web into a step by step quick tutorial both for myself, and others to use to make it easier when wanting to set this up across servers.

It’s a pretty handy addition to any administration tool kit as it cuts down on time ssh’ing in and manually running this, and is especially useful because it’s got logging so you only have to login if there was an issue!

** nb assumes a proper postfix / default setup.

INSTRUCTIONS

** nb assumes a proper postfix / default setup.

1) SSH to server

2) login / su to root

3) issue these commands:

# nano /root/autoupd

4) paste these items in

#!/bin/bash
tmpfile=$(mktemp)
hostname=$(hostname)
ourtime=`date +"%m-%d-%y"`
echo "APT UPDATE RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude update >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "APT UPGRADE RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude -y full-upgrade >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "APT CLEAN RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude clean >> ${tmpfile} 2>&1
mail -s "[${ourtime}] - [${hostname} patches]" root < ${tmpfile}
rm -f ${tmpfile}

5) issue this for your aliases file

# nano /etc/aliases

6) make sure this exists:

root: mail@yourdomain.com

replacing with your proper email address, obviously.

7) run newaliases to ensure functionality

# newaliases

8) restart postfix

# service postfix restart

9) test the script

# chmod +x /root/autoupd
# /root/autoupd

10) you should now have an email in your inbox with the results, if not grab a coffee and start troubleshooting.

11) now you want to make this run daily by copying it to your daily cron directory and make it executable again, just incase something changed.

# cp /root/autoupd /etc/cron.daily/autoupd
# chmod +x /etc/cron.daily/autoupd

12) that’s it, wait for the email notifications!

Fixing MySQL Error 1064 with PHPList when selecting new criteria

Today we had to fix a clients PHPlist. There was an error in their mysql select statement for whatever reason – whether it was their setup (they had some really weird group names and country names) or something with PHPList. Took us a while to figure it out, but as it turns out someone else had the same issue.

Basically the fix is this:

# nano /lists/admin/send_core.php

Find this

if (is_array($_POST[“criteria_values”])) {
$values = join(“, “,$_POST[“criteria_values”]);
} else {
$values = $_POST[“criteria_values”];
}

and replace it with this

if (is_array($_POST[“criteria_values”])) {
# The following code checks for null values in the criteria_attribute array and removes them
$values = $_POST[“criteria_values”];
foreach ($values as $key=>$value) {
if (!$value) {
array_splice($values, $key, 1); // Remove null value from array
}
}
$values = join(“, “,$values);
# $values = join(“, “,$_POST[“criteria_values”]);
} else {
$values = $_POST[“criteria_values”];
}

Now everything should work, with no more mysql errors!

Getting Sendmail to work with Rogers and Smarthost settings

I didn’t do this myself so I can’t vouch for it, but there was a recent discussion on one of the mailing lists I’m on about getting Sendmail to work with Rogers Smarthost settings.

Apparently this howto:

http://www.newthink.net/2007/05/18/smarthost-authentication-with-sendmail/

Will get you going, but there is one critical change you must make as determined by the Hugo on the mailing list.

Don’t forget to use smtp-rog.mail.yahoo.com in authinf and not smtp.broadband.rogers.com!

Also, if you want to use an external authinfo file, add this to your sendmail.mc file.

FEATURE(`authinfo’, `hash -o /etc/mail/authinfo.db’)dnl

Again, I didn’t try this myself, but I know some of you use Rogers and this may come in handy.

Another Reference on SMTP and Rogers Smarthost with Sendmail is here.