Created
December 8, 2015 06:50
-
-
Save ChatchaiJ/a57ebf459bab668f18b6 to your computer and use it in GitHub Desktop.
Get list of packages to be updated on debian system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ********************************************************************* # | |
# pkgupdate : script for calling from crontab to update debian # | |
# packages on a machine using apt-get # | |
# Mainly this is a two commands # | |
# # | |
# apt-get update && apt-get upgrade -y -d upgrade # | |
# # | |
# but made readable report from the output of those # | |
# two commands # | |
# # | |
# version 0.1 : cj (2003-12-26) initial # | |
# version 0.1a : cj (2004-07-22) the one that work. # | |
# version 0.1b : cj (2004-08-08) improve report message # | |
# version 0.1c : cj (2005-05-16) mail should be sent to all sysadmin # | |
# ********************************************************************* # | |
HOST=`hostname` | |
DATE=`date +%Y%m%d` | |
DATE2=`date` | |
LOG=`mktemp /tmp/.pkgupdate.XXXXXX` | |
ADMIN="sysadmin@localhost" | |
sudo apt-get update > $LOG | |
sudo apt-get -y -d upgrade >> $LOG | |
line=`cat $LOG | grep upgraded | grep installed | grep remove | sed -e 's/packages//'` | |
upgrade=`echo $line | cut -f1 -d' '` | |
install=`echo $line | cut -f3 -d' '` | |
remove=`echo $line | cut -f6 -d' '` | |
keptback=`echo $line | cut -f10 -d' '` | |
RESULT="$upgrade,$keptback,$remove,$install" | |
SUBJ="$DATE $HOST ($RESULT) pkgupdate" | |
( cat <<EOT | |
Debian packages update for '$HOST' on "$DATE2" | |
==================================================================== | |
Summary: | |
Upgrade: $upgrade | |
KeptBack: $keptback | |
Remove: $remove | |
Install: $install | |
==================================================================== | |
Detail: | |
EOT | |
cat $LOG | |
) | mail -s "$SUBJ" $ADMIN | |
rm -f $LOG | |
# ********************************************************************* # | |
# end of script # | |
# ********************************************************************* # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment