-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-dpkglog-upgrade
executable file
·57 lines (48 loc) · 2.96 KB
/
send-dpkglog-upgrade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# ====================================================
# send-dpkglog-upgrade - Permette di analizzare i log con
# gli aggiornamenti settimanali e invia una email
# riassuntiva alla maling list
# ====================================================
# @authors: Massimo Barbieri ([email protected])
# Alessandro Alboni ([email protected])
# (Add your name if you contribute)
# ====================================================
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU GENERAL PUBLIC LICENSE
# License as published by the Free Software Foundation; either
# version 3 of the License, or any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the GNU General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
###########################################################################
DESTINATARIO="hackers@XXXXXXXX" #Correggere indirizzo prima di eseguire
OGGETTO="Riepilogo aggiornamenti - settimana `date +%Y/%W`"
EMAILMESSAGE="/tmp/emailmessage.txt"
#TODO: in teoria questa riga si può eliminare poiché il file viene riscritto
# ad ogni esecuzione
rm -rf $EMAILMESSAGE
#TODO: Aggiungere altre info utili al preambolo (ora esecuzione, errori ecc.)
echo "Questa email è un messaggio automatico generato dallo script" > $EMAILMESSAGE
echo "$0 in esecuzione sul server del LUG Scandiano." >> $EMAILMESSAGE
echo "Lo script serve per informarti settimanalmente sullo stato di" >> $EMAILMESSAGE
echo "aggiornamento dei pacchetti presenti sul server." >> $EMAILMESSAGE
echo "-------------------------------------------------------------------" >> $EMAILMESSAGE
echo "NOME SCRIPT: $0" >> $EMAILMESSAGE
echo "DATA ESECUZIONE: `date`" >> $EMAILMESSAGE
echo "ERRORI: (servizio non attivo)" >> $EMAILMESSAGE
echo "GIORNI ANALIZZATI: dal `date +%Y-%m-%d -d '6 day ago'` al `date +%Y-%m-%d` compresi" >> $EMAILMESSAGE
echo "-------------------------------------------------------------------" >> $EMAILMESSAGE
# TODO: I duplicati non sempre vengono riconosciuti correttamente a causa
# dell'orario differente. Si potrebbe inserire nella catena dei comandi awk
# per eliminare la colonna dell'ora (forse inutile al nostro scopo).
# TODO: Il comando cat analizza solo i log non compressi. Sono sufficienti per
# avere uno storico settimanale degli upgrade?
cat /var/log/dpkg.* |grep 'install\|upgrade' | grep "$(date +%Y-%m-%d)\|$(date +%Y-%m-%d -d '1 day ago')\|$(date +%Y-%m-%d -d '2 day ago')\|$(date +%Y-%m-%d -d '3 day ago')\|$(date +%Y-%m-%d -d '4 day ago')\|$(date +%Y-%m-%d -d '5 day ago')\|$(date +%Y-%m-%d -d '6 day ago')" | grep -v status | grep -v trigproc | uniq >> $EMAILMESSAGE
mail -s "$OGGETTO" "$DESTINATARIO" < $EMAILMESSAGE
logger Inviata email con i log degli aggiornamenti -t LUG
exit 0