Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
regular updating portage by script (with logfile)
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
tarwin
n00b
n00b


Joined: 01 Oct 2003
Posts: 11
Location: Germany

PostPosted: Wed Oct 01, 2003 8:57 pm    Post subject: regular updating portage by script (with logfile) Reply with quote

Hi

i hope this is the right forum, if not please move it to the right spot.
I wrote a little script, and thought i should share it with the world...
and i hope the gentoo forum is the right place :)

Its a script that, when its lauched, runs an "emerge sync" and then,
well analyses the output, writing in a logfile what was changed,
what was deleted and the general rsync stats...
If does very well as a cronjob... i use it to update my portage tree weekly.

Well the program itself is a little slow... under perl it would do MUCH better.... to late for that.

Code:

#!/bin/bash

# script ment to use with cron to update portage on regular basis.
# logfile is written in /var/log/updportage.log
# exept for the logfile it generates no output (hopefully :) )

if [ -f /var/log/updportage.log ]
then
   sleep 0
else    
   touch /var/log/updportage.log
fi   

main=`emerge sync`

IFS=$'\n'
line='0'
tmpline='0'
timecount='0'
rsyncflag='0'
beginflag='0'

for line in $main
do      
   case "$rsyncflag" in
   0)
      if [ "`echo $line | tr -s ' ' ':' | cut -b 1 | grep ':'`" = ":" ] || [ "`echo $line | cut -c1 | grep d`" = "d" ] && [ $line != '' ]
      then
         if [ "`echo $tmpline | grep timestamp`" != "" ]
         then
            timecount=`expr $timecount + 1`

         elif [ "`echo $line | tr -s ' ' ':' | cut -f2 -d':'`" = "deleting" ] || [ "`echo $line | tr -s ' ' ':' | cut -f1 -d':'`" = "deleting" ] 
         then
            deleted="$deleted $line \n"
         
         elif [ "`echo $line | tr -d ' ' | cut -c1-6`" = "arena:" ]
         then
            rsyncflag='1'
            
         else
            new="$new $tmpline §"
         fi

      fi
   ;;
   1)
      rsyncnew="$rsyncnew $line \n"
   ;;
   esac
   tmpline=$line
done

rsyncflag='0'
IFS='§'
for line in $new
do
   if [ "`echo -e $line | tr -d ' ' | cut -b1-9`" = "receiving" ]
   then
      beginflag=1
   elif [ "$beginflag" = "1" ]
   then
   
      if [ "$rsyncflag" = "1" ] || [ "`echo -e $line | tr -d ' ' | cut -b1-6`" = "arena:" ]
      then
         rsyncflag=1

      elif [ "`echo -e $line | cut -c1-2`" != '  ' ] && [ "`echo -e $line | tr -d ' ' | cut -c1-8`" != "deleting" ]
      then
      newsorted="$newsorted $line \n"

      else
         trash="$trash $line \n"
      fi
   fi
done

echo > /var/log/updportage.log
log=`date`
log="$log \n\n emerge sync updated: \n\n $newsorted \n emerge sync deleted: \n\n $deleted \n rsync Output \n\n $rsyncnew \n"
echo -e $log >> /var/log/updportage.log



Just copy&paste the code into an empty text-file and don´t forget to set
the "executable" permission (chmod 755).
Hope that the script works on your machine as good as it runs on mine...

Gentoo rulez!!

Tarwin
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