FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 06-12-2008, 02:30 PM
Adrian Revill
 
Default Cobbler reposync cron script

Just in case anyone needs a script to run cobbler reposync from cron,
here is one i have written. It runs each repo in turn, and gives each a
number of tries (10) to over come problems with failing syncs.


#!/bin/bash

TRIES=10 # number of times to try and run reposync
LOGFILE="/var/log/cobbler/cobbler_reposync.log"

function running {
PID=$(ps ax| awk '/cobbler reposync/ && !/awk/ {print ($1)}')
if [ -z $PID ]
then
log "cobbler reposync is not running"
return 1
fi
log "cobbler reposync is running PID=$PID"
return 0
}

function log {
logger -t "COBBLER_REPOSYNC" -- $1
}

function run {
try=1
ret=1
while [ $try -le $TRIES ]
do
running
ok=$?
if [ $ok -eq 0 ]
then
log "Already running, aborting"
break
fi
log "Attempt $try for $1"
cobbler reposync --only=$1 2>&1 >> $LOGFILE
ret=$?
if [ $ret -eq 0 ]
then
break
fi
log "Attempt $try failed"
try=$[ $try + 1 ]
done
if [ $ret -eq 0 ]
then
log "Compleated $1"
else
log "Too many trys or already running, giving up on $1"

fi
}

log "Starting"
mv $LOGFILE $LOGFILE.1

for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
do
run $name
done

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 02:46 PM
Michael DeHaan
 
Default Cobbler reposync cron script

Adrian Revill wrote:
Just in case anyone needs a script to run cobbler reposync from cron,
here is one i have written. It runs each repo in turn, and gives each
a number of tries (10) to over come problems with failing syncs.


#!/bin/bash

TRIES=10 # number of times to try and run reposync
LOGFILE="/var/log/cobbler/cobbler_reposync.log"

function running {
PID=$(ps ax| awk '/cobbler reposync/ && !/awk/ {print ($1)}')
if [ -z $PID ]
then
log "cobbler reposync is not running"
return 1
fi
log "cobbler reposync is running PID=$PID"
return 0
}

function log {
logger -t "COBBLER_REPOSYNC" -- $1
}

function run {
try=1
ret=1
while [ $try -le $TRIES ]
do
running
ok=$?
if [ $ok -eq 0 ]
then
log "Already running, aborting"
break
fi
log "Attempt $try for $1"
cobbler reposync --only=$1 2>&1 >> $LOGFILE
ret=$?
if [ $ret -eq 0 ]
then
break
fi
log "Attempt $try failed"
try=$[ $try + 1 ]
done
if [ $ret -eq 0 ]
then
log "Compleated $1"
else
log "Too many trys or already running, giving up on $1"

fi
}

log "Starting"
mv $LOGFILE $LOGFILE.1

for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
do
run $name
done

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools


Nice! Do you mind if I put this in a 'contrib' directory in cobbler's
version control so other people can find it later?


We can mention this on the Wiki too.

One small change I'd make is to make the last awk line run 'cobbler repo
list' instead of grepping the file, that way
it works regardless of the storage backend -- though everyone pretty
much uses the stock one.


--Michael

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 03:24 PM
Robin Bowes
 
Default Cobbler reposync cron script

Michael DeHaan wrote:

Adrian Revill wrote:

for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
do
run $name
done


One small change I'd make is to make the last awk line run 'cobbler repo
list' instead of grepping the file, that way
it works regardless of the storage backend -- though everyone pretty
much uses the stock one.


As I always say, if it looks too complicated, there's probably a better
way to do it:


for name in `cobbler repo list`
do
run $name
done

R.

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 03:38 PM
"Sandor W. Sklar"
 
Default Cobbler reposync cron script

On Jun 12, 2008, at 8:24 AM, Robin Bowes wrote:


Michael DeHaan wrote:

Adrian Revill wrote:

for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
do
run $name
done
One small change I'd make is to make the last awk line run 'cobbler
repo list' instead of grepping the file, that way
it works regardless of the storage backend -- though everyone
pretty much uses the stock one.


As I always say, if it looks too complicated, there's probably a
better way to do it:


for name in `cobbler repo list`
do
run $name
done



... and I'm not sure why:

cobbler reposync > /dev/null

... isn't sufficient. Is there an advantage to doing the repos one at
a time? I've got the above. If everything works, I get no email. If
there is a problem, it gets sent to stderr, so I get email.


-s-

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 03:43 PM
Matt Hyclak
 
Default Cobbler reposync cron script

On Thu, Jun 12, 2008 at 08:38:42AM -0700, Sandor W. Sklar enlightened us:
> On Jun 12, 2008, at 8:24 AM, Robin Bowes wrote:
>
> >Michael DeHaan wrote:
> >>Adrian Revill wrote:
> >>>for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
> >>>do
> >>> run $name
> >>>done
> >>One small change I'd make is to make the last awk line run 'cobbler
> >>repo list' instead of grepping the file, that way
> >>it works regardless of the storage backend -- though everyone
> >>pretty much uses the stock one.
> >
> >As I always say, if it looks too complicated, there's probably a
> >better way to do it:
> >
> >for name in `cobbler repo list`
> >do
> > run $name
> >done
>
>
> ... and I'm not sure why:
>
> cobbler reposync > /dev/null
>
> ... isn't sufficient. Is there an advantage to doing the repos one at
> a time? I've got the above. If everything works, I get no email. If
> there is a problem, it gets sent to stderr, so I get email.
>

cobbler stops processing the remaining repos if it hits an error in one, so
doing them one at a time allows the others to complete.

Matt

--
Matt Hyclak
Department of Mathematics
Department of Social Work
Ohio University
(740) 593-1263

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 03:51 PM
"Sandor W. Sklar"
 
Default Cobbler reposync cron script

On Jun 12, 2008, at 8:43 AM, Matt Hyclak wrote:

On Thu, Jun 12, 2008 at 08:38:42AM -0700, Sandor W. Sklar
enlightened us:


... and I'm not sure why:

cobbler reposync > /dev/null

... isn't sufficient. Is there an advantage to doing the repos one
at
a time? I've got the above. If everything works, I get no email.
If

there is a problem, it gets sent to stderr, so I get email.



cobbler stops processing the remaining repos if it hits an error in
one, so

doing them one at a time allows the others to complete.


Ah, cool, I didn't realize that. Now it makes sense!

Thanks,
-s-

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 03:53 PM
Michael DeHaan
 
Default Cobbler reposync cron script

Matt Hyclak wrote:

On Thu, Jun 12, 2008 at 08:38:42AM -0700, Sandor W. Sklar enlightened us:


On Jun 12, 2008, at 8:24 AM, Robin Bowes wrote:



Michael DeHaan wrote:


Adrian Revill wrote:


for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
do
run $name
done

One small change I'd make is to make the last awk line run 'cobbler
repo list' instead of grepping the file, that way
it works regardless of the storage backend -- though everyone
pretty much uses the stock one.

As I always say, if it looks too complicated, there's probably a
better way to do it:


for name in `cobbler repo list`
do
run $name
done


... and I'm not sure why:

cobbler reposync > /dev/null

... isn't sufficient. Is there an advantage to doing the repos one at
a time? I've got the above. If everything works, I get no email. If
there is a problem, it gets sent to stderr, so I get email.





cobbler stops processing the remaining repos if it hits an error in one, so
doing them one at a time allows the others to complete.



That's something we can do in the code later, no doubt. Until then, this
does the job. The great thing is it doesn't really matter if it's Python
or shell as long as it works


I'll see about adding a --retries to reposync in the future. I believe
there is already an RFE for a flag to skip the ones that

fail without blocking the rest.



Matt




_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 07:03 PM
Robin Bowes
 
Default Cobbler reposync cron script

Michael DeHaan wrote:

Matt Hyclak wrote:
cobbler stops processing the remaining repos if it hits an error in
one, so doing them one at a time allows the others to complete.



That's something we can do in the code later, no doubt. Until then, this
does the job. The great thing is it doesn't really matter if it's Python
or shell as long as it works


I'll see about adding a --retries to reposync in the future. I believe
there is already an RFE for a flag to skip the ones that

fail without blocking the rest.


I think that should be the default - report if a repo fails, but keep going.

In a similar vein to Sandor, I would think that something like the
following would suffice in most cases:


for repo in `cobbler repo list`
do
cobbler reposync --only=${repo} > /dev/null
done

I'd actually like to see much less output. For example, only reporting
if any RPMS were downloaded or removed.


R.

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-12-2008, 07:06 PM
Michael DeHaan
 
Default Cobbler reposync cron script

Robin Bowes wrote:

Michael DeHaan wrote:

Matt Hyclak wrote:
cobbler stops processing the remaining repos if it hits an error in
one, so doing them one at a time allows the others to complete.



That's something we can do in the code later, no doubt. Until then,
this does the job. The great thing is it doesn't really matter if
it's Python or shell as long as it works


I'll see about adding a --retries to reposync in the future. I
believe there is already an RFE for a flag to skip the ones that

fail without blocking the rest.


I think that should be the default - report if a repo fails, but keep
going.


In a similar vein to Sandor, I would think that something like the
following would suffice in most cases:


for repo in `cobbler repo list`
do
cobbler reposync --only=${repo} > /dev/null
done

I'd actually like to see much less output. For example, only reporting
if any RPMS were downloaded or removed.


R.

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools


Sounds reasonable.

As far as much less output goes, and the failure handling options, this
is a fairly easy patch to make if someone wants to take a crack at it.
Otherwise, it's another item on the big list of great requests


Hop on #cobbler and I'll even provide help.

--Michael


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-13-2008, 01:01 PM
Adrian Revill
 
Default Cobbler reposync cron script

Yes feel free to add it.

I tried the change to use "cobbler list repo" and it works fine.


Michael DeHaan wrote:
>
> Adrian Revill wrote:
>> Just in case anyone needs a script to run cobbler reposync from cron,
>> here is one i have written. It runs each repo in turn, and gives each
>> a number of tries (10) to over come problems with failing syncs.
>>
>> #!/bin/bash
>>
>> TRIES=10 # number of times to try and run reposync
>> LOGFILE="/var/log/cobbler/cobbler_reposync.log"
>>
>> function running {
>> PID=$(ps ax| awk '/cobbler reposync/ && !/awk/ {print ($1)}')
>> if [ -z $PID ]
>> then
>> log "cobbler reposync is not running"
>> return 1
>> fi
>> log "cobbler reposync is running PID=$PID"
>> return 0
>> }
>>
>> function log {
>> logger -t "COBBLER_REPOSYNC" -- $1
>> }
>>
>> function run {
>> try=1
>> ret=1
>> while [ $try -le $TRIES ]
>> do
>> running
>> ok=$?
>> if [ $ok -eq 0 ]
>> then
>> log "Already running, aborting"
>> break
>> fi
>> log "Attempt $try for $1"
>> cobbler reposync --only=$1 2>&1 >> $LOGFILE
>> ret=$?
>> if [ $ret -eq 0 ]
>> then
>> break
>> fi
>> log "Attempt $try failed"
>> try=$[ $try + 1 ]
>> done
>> if [ $ret -eq 0 ]
>> then
>> log "Compleated $1"
>> else
>> log "Too many trys or already running, giving up on $1"
>>
>> fi
>> }
>>
>> log "Starting"
>> mv $LOGFILE $LOGFILE.1
>>
>> for name in $(awk '/name:/ {print($2)}' /var/lib/cobbler/repos)
>> do
>> run $name
>> done
>>
>> _______________________________________________
>> et-mgmt-tools mailing list
>> et-mgmt-tools@redhat.com
>> https://www.redhat.com/mailman/listinfo/et-mgmt-tools
>
> Nice! Do you mind if I put this in a 'contrib' directory in cobbler's
> version control so other people can find it later?
>
> We can mention this on the Wiki too.
>
> One small change I'd make is to make the last awk line run 'cobbler repo
> list' instead of grepping the file, that way
> it works regardless of the storage backend -- though everyone pretty
> much uses the stock one.
>
> --Michael
>
> _______________________________________________
> et-mgmt-tools mailing list
> et-mgmt-tools@redhat.com
> https://www.redhat.com/mailman/listinfo/et-mgmt-tools
>
>

--
View this message in context: http://www.nabble.com/Cobbler-reposync-cron-script-tp17801508p17822886.html
Sent from the et-mgmt-tools mailing list archive at Nabble.com.

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 12:46 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org