Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Auto Notification of Portage Updates via Email (bash script)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
quikchaos
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jan 2003
Posts: 107
Location: Indianapolis, IN

PostPosted: Wed Apr 09, 2003 4:54 pm    Post subject: Auto Notification of Portage Updates via Email (bash script) Reply with quote

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
View user's profile Send private message
carl
n00b
n00b


Joined: 12 Mar 2003
Posts: 30
Location: Michigan, USA

PostPosted: Mon Apr 14, 2003 6:57 pm    Post subject: Reply with quote

Pretty cool script. I went ahead and installed it on my server. Nice job!
Back to top
View user's profile Send private message
quikchaos
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jan 2003
Posts: 107
Location: Indianapolis, IN

PostPosted: Mon Apr 14, 2003 7:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Narada
Guru
Guru


Joined: 12 Dec 2002
Posts: 300
Location: London, UK

PostPosted: Mon Apr 21, 2003 2:22 am    Post subject: Reply with quote

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
View user's profile Send private message
quikchaos
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jan 2003
Posts: 107
Location: Indianapolis, IN

PostPosted: Mon Apr 21, 2003 12:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 18155

PostPosted: Mon Apr 21, 2003 12:18 pm    Post subject: Reply with quote

v is the verbose option for emerge. The +nls and -build are what USE flags the ebuild uses.
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
Z?
Tux's lil' helper
Tux's lil' helper


Joined: 22 Jan 2003
Posts: 118
Location: Waterloo, Ontario, Canada

PostPosted: Sun May 25, 2003 6:43 am    Post subject: Reply with quote

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
View user's profile Send private message
Woland
Apprentice
Apprentice


Joined: 02 Aug 2002
Posts: 248
Location: Russian Jack, Alaska

PostPosted: Mon May 26, 2003 7:33 am    Post subject: Reply with quote

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
View user's profile Send private message
BlinkEye
Veteran
Veteran


Joined: 21 Oct 2003
Posts: 1046
Location: Gentoo Forums

PostPosted: Fri Nov 05, 2004 10:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum