12 November 2014
I want to have control over debian updates, but I don’t want to make them manually. So I decided to do it “half-automatic”. This means that they run automatically until user-input is needed. The whole prozess is recorded in logfiles and after the updates are done this script sends out emails.
This is the parser for the summary-email. it works for english ang german environments:
#!/usr/bin/perl
use strict;
if ( $#ARGV ne 0)
{
die "usage: $0 \n";
}
my $logfile = $ARGV[0];
my $upgrades = undef;
open(LOG,"< $logfile") or die "can't open logfile: $logfile";
while()
{
my $line = $_;
if($line =~ /The following packages will be upgraded/g)
{
$line = ;
while($line !~ /\d+ upgraded, \d+ newly installed, \d+ to remove and \d+ not upgraded/)
{
$upgrades = $upgrades . " " . $line;
$line = ;
}
}
if($line =~ /Die folgenden Pakete werden aktualisiert/g)
{
$line = ;
while($line !~ /\d+ aktualisiert, \d+ neu installiert, \d+ zu entfernen und \d+ nicht aktualisiert./)
{
$upgrades = $upgrades . " " . $line;
$line = ;
}
}
}
close(LOG);
$upgrades =~ s/^\s+//g;
$upgrades =~ s/\r+//g;
$upgrades =~ s/\n+//g;
if($upgrades =~ /^\s+$/g or $upgrades =~ /^$/g or $upgrades =~ /^\n$/g)
{
exit 0;
}
my @arr = split(/\s+/,$upgrades);
print "$upgrades \n";
exit $#arr + 1;
And this is our update-script:
#!/bin/bash
LOGDIR=/opt/update-logs
PARSER=/opt/bin/aptlogparser.pl
eval `ssh-agent -s`
ssh-add
export TERM="rxvt"
function update_customer
{
for host in $HOSTS
do
DAT=`date +%F-%R`
echo "KUNDE: $KUNDE"
script -c "ssh -l root $host \"export TERM=rxvt; export DEBIAN_FRONTEND=readline; echo $TERM; hostname; apt-get update; apt-get upgrade\""
test -e typescript && mv typescript $LOGDIR/$host-$DAT.log
UPDATES=`$PARSER $LOGDIR/$host-$DAT.log`
if [$? -ne 0]
then
echo "$host: $UPDATES" >> ${KUNDE}_EMAIL.txt
echo "" >> ${KUNDE}_EMAIL.txt
fi
done
DAT=`date +%F`
if [-e ${KUNDE}_EMAIL.txt]
then
cat ${KUNDE}_EMAIL.txt | mutt -s "Linux-Updates vom $DAT" -- $EMAIL
rm ${KUNDE}_EMAIL.txt
fi
}
HOSTS="websrv mailsrv"
EMAIL="bob@example.com"
KUNDE="customer1"
update_customer
HOSTS="linuxsrv1 linuxsrv2"
EMAIL="alice@example.com"
KUNDE="customer2"
update_customer
11 November 2014
GNU Octave is some kind of programming language for mathematical use cases. It’s mostly compatible with MATLAB and it’s Open-Source.
I just started to get familiar with GNU Octave and i really like it. Here i record my “first steps” and post my scripts..
11 November 2014
“Hipsters avoid labels and being labeled. However, they all dress the same and act the same and conform in their non-conformity. Doesn’t the fact that there is a hipster look go against all hipster beliefs?”.
Jonathan Touboul wrote this mathematic model which describes the “hippster-effect”
10 November 2014
With nice colors logfiles get more readable. I like the postfix-format of “multitail”.
multitail -CS postfix -f /var/log/mail.log:
7 November 2014
#include
int main()
{
printf("Hello World, this is my new blog\n");
return 0;
}