View previous topic :: View next topic |
Author |
Message |
quikchaos Tux's lil' helper
Joined: 29 Jan 2003 Posts: 107
|
Posted: Wed Apr 09, 2003 4:54 pm Post subject: Auto Notification of Portage Updates via Email (bash script) |
|
|
I am sure it has been done before, but I decided to make a script from scratch. I am kind of new to bash scripts, so bear with me. This was good practice.
I have commented the script fairly well for those who want to tweak it more. As it stands right now, this script works flawlessly.
Be sure to criticize my technique all you want, and feel free to give me some pointers on making this better. Thanks and enjoy!
Code: | #!/bin/bash
# Date: 04/08/2003
# Title: Gentoo Server Portage Update Notification (notifyupdate.sh)
# Author: Andrew Heacock
# E-mail: aheacock@diamondchain.com
#
# This script updates your servers portage tree, then looks for
# possible updates. If any are found, it will e-mail the list of
# updates to '$emailto'. This script uses sendmail to deliver
# e-mails, so be sure your MTA has a proper link to sendmail.
#
# Please be sure to change the User Variables to suit your needs.
#
# I find this useful by putting it in your crontab. I set mine to
# run at 6:00AM and 12:00PM everyday as to not hog the rsync
# servers and not have to run to the server to check for updates.
#
# Crontab Example:
# 0 6 * * * root /etc/notifyupdate.sh
# 0 12 * * * root /etc/notifyupdate.sh
# User Variables
templog=/tmp/notifyupdate.tmp
sendmail=/usr/lib/sendmail
emailto="someuser@somedomain.com"
emailfrom="Gentoo Server Admin"
emailsubject="*** Portage Updates ***"
#Get the current portage tree and update library links
emerge sync >/dev/null &&
env-update >/dev/null &&
ldconfig >/dev/null
# Look for any "world" wide updates and put them in '$templog'
#
# WARNING: Do not use the following command without the '-p' switch
# on a production server. Always review updates before building and
# merging them into the system.
emerge --deep -p world | grep '\[*\]' > $templog
# Email the log file if it is not empty
if [ -s $templog ]; then
(
cat << EOF
To: $emailto
Subject: $emailsubject
Here are packages that have available updates:
EOF
cat $templog
) | $sendmail -F"$emailfrom" $emailto & rm $templog;
else
rm $templog & exit
fi |
_________________ "Whether you think you can or you think you can't... you're right." -- Henry Ford |
|
Back to top |
|
|
carl n00b
Joined: 12 Mar 2003 Posts: 30 Location: Michigan, USA
|
Posted: Mon Apr 14, 2003 6:57 pm Post subject: |
|
|
Pretty cool script. I went ahead and installed it on my server. Nice job! |
|
Back to top |
|
|
quikchaos Tux's lil' helper
Joined: 29 Jan 2003 Posts: 107
|
Posted: Mon Apr 14, 2003 7:09 pm Post subject: |
|
|
I also found another script that essentially does the same thing, written in PHP.
https://forums.gentoo.org/viewtopic.php?t=12448&highlight=portage+update+email
It supports multiple email addresses to send the update info to. I haven't tried it in my bash script yet. Haven't had a need to. But if you have a handful of Admins that manage the Gentoo server, that might be helpful. _________________ "Whether you think you can or you think you can't... you're right." -- Henry Ford |
|
Back to top |
|
|
Narada Guru
Joined: 12 Dec 2002 Posts: 300 Location: London, UK
|
Posted: Mon Apr 21, 2003 2:22 am Post subject: |
|
|
The line: Code: | emerge --deep -p world | grep '\[*\]' > $templog | can be changed to: Code: | emerge -Duvp world | grep ebuild > $templog | . _________________ http://dhruba.name/ |
|
Back to top |
|
|
quikchaos Tux's lil' helper
Joined: 29 Jan 2003 Posts: 107
|
Posted: Mon Apr 21, 2003 12:15 pm Post subject: |
|
|
Thanks Narada. My I ask what the trailing messages mean with the -v? For example:
Code: | root@monitor: pty/s0: 1 files 14Kb -> emerge -Duvp world
These are the packages that I would merge, in order:
Calculating world dependencies ...done!
[ebuild U ] sys-apps/gawk-3.1.2-r3 [3.1.1-r1] +nls -build
[ebuild U ] sys-apps/sed-4.0.7 [4.0.6] +nls -static -build
[ebuild U ] sys-apps/procps-3.1.8 [2.0.10-r1] -selinux
[ebuild U ] sys-apps/slocate-2.7-r2 [2.7-r1]
|
What does the +nls -build stuff mean? _________________ "Whether you think you can or you think you can't... you're right." -- Henry Ford |
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Mon Apr 21, 2003 12:18 pm Post subject: |
|
|
v is the verbose option for emerge. The +nls and -build are what USE flags the ebuild uses. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
Z? Tux's lil' helper
Joined: 22 Jan 2003 Posts: 118 Location: Waterloo, Ontario, Canada
|
Posted: Sun May 25, 2003 6:43 am Post subject: |
|
|
You could also just replace the entire script with:
Code: | emerge rsync > /dev/null && emerge -Dvup world | grep ebuild |
in your crontab entry, since cron'll be kind enough to e-mail you the output from the command (at least, dcron does -- not sure about the other crons...)
But thanks for the tip -- I'd been wondering if there was an easy way to do this... this post helped me figure out the right command... |
|
Back to top |
|
|
Woland Apprentice
Joined: 02 Aug 2002 Posts: 248 Location: Russian Jack, Alaska
|
Posted: Mon May 26, 2003 7:33 am Post subject: |
|
|
Have to weigh in with my own script
Its beauty (at least to me) is that it goes about its buisness every other day, which I belive is the suggested syncing interval for the normal administrator.
It is designed to be dropped into /etc/cron.daily with vixie cron, other cron users just set it to run each day from your crontabs or whatever.
You need to emerge mailx for it to run, (a 240 kB download which builds a 81kB executable) otherwise it does not care about your MTA. The very last line sets the refault recipient to root, but that is easily changed. If you really need multiple reciepients, that can be easily done. Message me, and I will do it. |
|
Back to top |
|
|
BlinkEye Veteran
Joined: 21 Oct 2003 Posts: 1046 Location: Gentoo Forums
|
Posted: Fri Nov 05, 2004 10:01 am Post subject: |
|
|
this works too:
root # crontab -e
Code: | 00 03 * * * emerge sync >/dev/null 2>&1 && emerge -fDu world >/dev/null 2>&1
20 03 * * * emerge -pvDu world |
i forgot why but i had to seperate these too line. at three in the morning portage syncs its database, downloads every package it would neen for a deep update and sends me a mail at 03:20 with the packages it wants to update. _________________ Easily backup up your system? klick
Get rid of SSH Brute Force Attempts / Script Kiddies klick |
|
Back to top |
|
|
|