Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Automatic notification of updates
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
Kosmo
n00b
n00b


Joined: 24 May 2002
Posts: 74

PostPosted: Fri May 24, 2002 11:32 pm    Post subject: Automatic notification of updates Reply with quote

I wrote a little script for in cron.{hourly,daily,weekly,monthly} (depending on how paranoid you are) that should mail root telling when there are updates...

Code:
#!/bin/sh

# First synchronize the portage tree
emerge rsync > /dev/null

# Make a pretend update of 'world'
# The grep is to try it not to send any mails when it can't find any new things
emerge -p -u world | grep ebuild


I know it works on the shell, but cron did not run my daily yet... :-)
Back to top
View user's profile Send private message
dafearless
n00b
n00b


Joined: 29 May 2002
Posts: 5
Location: Netherlands

PostPosted: Thu May 30, 2002 9:07 pm    Post subject: Reply with quote

I have made a simular script in perl that will let you alse choose witch packages you wish to upgrade an then start the upgrading process

Code:

#!/usr/bin/perl
$|=1 ;
use strict ;

my $search ;
my $replace ;
my $tmpfl = "/tmp/upgrade.tmp" ;

#Defining Subroutines
#
sub get_info();
sub show_info();
sub selection();
sub clear();
sub filereplace();
sub start();

clear ;

# Let's emerge sync te portage tree
#
print "Synchronize the Portage tree \n" ;
my $updrsync = `emerge rsync` ;

get_info ;
show_info ;

#Here we wil get the info of which packages are ready to be upgraded
#
sub get_info() {
   open(TMP,">$tmpfl");
   print "Making pretend update of world\n" ;
   my @getupdates = `emerge -p -u world` ;         ## This is the commando that i will use to see what the upgrades are
   my $i = 0 ;
   foreach (@getupdates) {
      if (/\[ebuild\s+\\[32/) {
         chomp ;
         my @spl = split /]/ ;
         my @final = split /\// ;
         my @last = split (/\s/,$final[1]) ;
         print TMP "  $i\t$last[0] (NEW)\n" ;
         $i++ ;
      }
      if (/\[ebuild\s+\\[36/) {
         chomp ;
         my @spl = split /]/ ;
         my @final = split /\// ;
         my @last = split (/\s/,$final[1]) ;
               print TMP "  $i\t$last[0] (UPDATE)\n" ;
         $i++ ;
      }
   }
   close(TMP);
}

#Here we will print the packges that can be upgraded on the screen
#
sub show_info() {
   clear ;
   open (TMP2,"<$tmpfl");
   foreach(<TMP2>) {
      print $_ ;               
   }
   close(TMP2) ;
   selection ;
}


#Here you can make you choice of what you want to upgrade
#
sub selection() {
   print "Which Packages do you want to Upgrade or type quit to exit or type go to start upgrading the selected programs.\n" ;
   my $antwoord = <STDIN> ;
   chomp($antwoord);

   if ($antwoord eq "go") {
      &start ;
      exit 1 ;
   }
 
    if ($antwoord eq "quit") {
      exit 0 ;
   }
   
   open(OUT, "$tmpfl");
   my @data2 = <OUT>;
   my $ster = "x $antwoord" ;
   my $gster = "  $antwoord" ;
   foreach (@data2) {
      if (/^$gster/) {
         &filereplace("$gster","$ster") ;
      }
      elsif (/^$ster/) {
         &filereplace("$ster","$gster") ;
      }
   }
   close(OUT);
   show_info ;
}

#In this part we wil add or remove a X to the tmp file
#
sub filereplace() {
   ($search,$replace) = @_ ;

   open(OUT, "$tmpfl");
   my @data = <OUT>;
   close(OUT) ;

   open(OUT, ">$tmpfl") ;
   foreach my $dataline (@data) {
      $dataline =~ s/$search/$replace/gi ;
      print OUT $dataline ;
   }
   close(OUT) ;
   show_info;
}

#And here we wil start the upgrade :P
#
sub start() {
   open(OUT, "$tmpfl") ;
   my @data3 = <OUT> ;
   close(OUT) ;

   my @ARRAY ;

   print "Upgrading the folowing packages\n" ;
   foreach (@data3) {
      if (/^x/) {
         my @spl = split(/\s/) ;
         print "\t$spl[2]\n" ;
         my @spl2 = split(/\./,$spl[2]);
         chop($spl2[0]) ;
         chop($spl2[0]) ;
         my $value = "$spl2[0] ";
         $ARRAY[++$#ARRAY] = $value ;
      }
   }
   my $emerge = `emerge -u @ARRAY`  ;
   print $emerge ;
}

#Here we will clean the screan.
#
sub clear() {
   my $clear = `clear` ;
   print $clear ;
}


let me know what you think of it or if you find any inprovements let me also know :)
Back to top
View user's profile Send private message
samureye
n00b
n00b


Joined: 11 Jul 2002
Posts: 15

PostPosted: Thu Jul 11, 2002 11:19 pm    Post subject: Reply with quote

Looks good! You might want to make the 'emerge rsync' optional (maybe an argument on the command line so people with low bandwidth don't get forced to run it?).

Would you be able to send me the perl script? I'm having a bit of difficulty weeding out some weird characters that have been chucked in there by the forum.

Good work tho! :)
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Fri Jul 12, 2002 12:29 am    Post subject: Reply with quote

Yeah, maybe post it without the code tags...

samureye wrote:
Looks good! You might want to make the 'emerge rsync' optional (maybe an argument on the command line so people with low bandwidth don't get forced to run it?).

Would you be able to send me the perl script? I'm having a bit of difficulty weeding out some weird characters that have been chucked in there by the forum.

Good work tho! :)
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 17455

PostPosted: Fri Jul 12, 2002 1:35 am    Post subject: Reply with quote

Highlighting it and copying it to nedit or something won't work?
_________________
Slowly I turned. Step by step.
Back to top
View user's profile Send private message
steblublu
n00b
n00b


Joined: 12 Jul 2002
Posts: 49
Location: montreal, canada

PostPosted: Wed Jul 17, 2002 4:46 am    Post subject: strip control codes Reply with quote

arkane wrote:
Yeah, maybe post it without the code tags...


Copy to KEdit, save the file. It will strip the control codes.
Back to top
View user's profile Send private message
Zippo
n00b
n00b


Joined: 21 Jul 2002
Posts: 6

PostPosted: Sun Jul 21, 2002 11:54 pm    Post subject: Reply with quote

It'd be a lot easier to code around emerge if you would set the NOCOLOR environment var to "true".

$ENV{NOCOLOR} = 'true';

That way, you wouldn't have to dig for ANSI codes in the output...
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Wed Jul 24, 2002 3:07 am    Post subject: Re: strip control codes Reply with quote

steblublu wrote:
arkane wrote:
Yeah, maybe post it without the code tags...


Copy to KEdit, save the file. It will strip the control codes.


Unfortunately Mozilla doesn't like to copy stuff out of the code boxes. :(

it treats it alot like a JPEG.. at least on my machine. Does anyone else have this problem? (well, doesn't allow you to save it, but it won't let you highlight in there)
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Wed Jul 24, 2002 3:08 am    Post subject: Re: strip control codes Reply with quote

arkane wrote:
steblublu wrote:
arkane wrote:
Yeah, maybe post it without the code tags...


Copy to KEdit, save the file. It will strip the control codes.


Unfortunately Mozilla doesn't like to copy stuff out of the code boxes. :(

it treats it alot like a JPEG.. at least on my machine. Does anyone else have this problem? (well, doesn't allow you to save it, but it won't let you highlight in there)



Nevermind... it looks like the recent upgrade I did of mozilla fixed that.
alright, I'm golden :)
Back to top
View user's profile Send private message
sebest
Apprentice
Apprentice


Joined: 03 Jul 2002
Posts: 163
Location: Paris - France

PostPosted: Fri Nov 21, 2003 3:22 pm    Post subject: Reply with quote

i have a similar script, but it only mail you when there is a new package to update, and show you the differences between last run.
http://gentoo.ovibes.net/gentoo-updates.cron
Code:

#!/bin/bash

#
# Sebastien ESTIENNE <sebest@ovibes.net>
# http://gentoo.ovibes.net
#

EMAIL="admin@myisp.com"

DIR="/var/cache/gentoo-updates"
VERSION="5"

if [ ! -d ${DIR} ]
then
    mkdir ${DIR}
fi

if [ -f ${DIR}/updates.new ]
then
    mv ${DIR}/updates.new ${DIR}/updates.old
else
    touch ${DIR}/updates.old
fi

emerge sync > ${DIR}/rsync.log
emerge -Up world | grep ebuild | sort >& ${DIR}/updates.new
diff -u0 ${DIR}/updates.old ${DIR}/updates.new | grep ebuild > ${DIR}/updates.diff


#
# creating mail
#
echo "Packages that need to be updaded:" > ${DIR}/updates.mail
cat ${DIR}/updates.new >> ${DIR}/updates.mail
echo >>  ${DIR}/updates.mail
echo "Differences between last run:" >> ${DIR}/updates.mail
cat ${DIR}/updates.diff >> ${DIR}/updates.mail
echo >> ${DIR}/updates.mail
echo "--" >> ${DIR}/updates.mail
echo $0 version ${VERSION} >> ${DIR}/updates.mail

if [ -s ${DIR}/updates.new ] && [ -s ${DIR}/updates.diff ]
then
#    NB_UPDATES=`wc -l ${DIR}/updates.new | cut -f 1 -d " "`
    mail -s "Gentoo Updates At `hostname`" ${EMAIL} < ${DIR}/updates.mail
fi


_________________
--
Seb aka "Mr Est"
Back to top
View user's profile Send private message
viperlin
Veteran
Veteran


Joined: 15 Apr 2003
Posts: 1317
Location: UK

PostPosted: Sat Nov 22, 2003 12:28 am    Post subject: Reply with quote

i also have a similar one, in php though:

Code:

#!/usr/bin/php -f
<?php

$subject='Subject: machine.name - checking for updates';

$notify[]='email@address.com';
$notify[]='email2@address.com';

set_time_limit(3600);

$msg.='Updating the source tree...'.chr(10);

$null=`/usr/bin/emerge sync`.chr(10).chr(10);
$msg.='Checking for updateable packages...'.chr(10).chr(10);

$msg.=`/usr/bin/emerge -U world -p -v`.chr(10).chr(10);
$msg.='Completed!';

$msg=str_replace(chr(8), '', $msg);
$msg=str_replace(chr(27), '', $msg);
$msg=str_replace('\|/-', '', $msg);
$msg=str_replace('\|/', '', $msg);
$msg=str_replace('|/-', '', $msg);
$msg=str_replace('/-', '', $msg);
$msg=str_replace('[36;01mU[0m ]', 'U ]', $msg);

foreach ( $notify as $e ) {
                mail($e, $subject, $msg, "Reply-To: reply@address.com");
        }

?>


hopefully you can see which parts to edit to use it. requires php and set a cronjob to run this (i have it run once a week)
Back to top
View user's profile Send private message
hulk2nd
Guru
Guru


Joined: 25 Mar 2003
Posts: 512
Location: Freiburg, Germany

PostPosted: Sat Nov 22, 2003 3:33 am    Post subject: Reply with quote

hi there,

excuse me, this is a little bit offtopic: please do not run cron scripts like these (especially with emerge sync included) hourly. you know that linux (gentoo) is free and the resources are limited. please keep in mind that it is voluntary to setup an rsync mirror and that there is always somebody behind who pays for that internet connection.

thanks and greets,
hulk
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