On Friday 20 October 2006 15:15, Logan Shaw wrote:
> On Thu, 19 Oct 2006, Chris Purves wrote:
> > I'm running sa-update from a bash script in /etc/cron.hourly but I keep
> > getting the following every time the script runs:
> >
> > run-parts: /etc/cron.hourly/sa-update exited with return code 1
> >
> > I believe this is because sa-update only returns error code 0 when
> > something has been updated so that you can append && restart spamd
> > command.
>
> The documentation says 1 means it successfully checked,
> but there was no new data.  0 means it found new data and
> successfully downloaded it.  Since 1 is an OK exit code that
> doesn't present a problem, you could do this:
>
>      sa-update || true
>
> "true" is a program that exits with a code of 0.
>
> Then again, presumably /etc/cron.hourly/sa-update is a script,
> not a symlink to /usr/bin/sa-update or something, so you could
> just add "exit 0" as the last line of the script.  If you just
> have sa-update in it alone, the script will exit with the code
> that sa-update exits with.
>
> If you want to get really fancy and ignore 1 but not
> ignore other non-zero exit codes, you can use this as your
> /etc/cron.hourly/sa-update script:
>
>       #! /bin/sh
>
>       # run and immediately capture exit code
>       sa-update
>       rc=$?
>
>       case "$rc" in
>       0|1)
>           rc=0
>           ;;
>       esac
>
>       exit "$rc"
>
> Hope that helps.

That's exactly what I was looking for.  I used your example to write a script 
that will run two sa-update commands.   If either returns an error code 
higher than 1, that will be reported (the second command will not run if the 
first doesn't exit with 0 or 1).  0 or 1 error codes will be reset to 0.   
Thanks for your help; I also learned some more about bash scripting.



#!/bin/sh

sa-update && /etc/init.d/spamassassin restart && echo "Spamassassin rules 
updated."
rc=$?

if [ "$rc" -le "1" ]; then
  sa-update --gpgkey D1C035168C1EBC08464946DA258CDB3ABDE9DC10 --channel 
saupdates.openprotect.com && /etc/init.d/spamassassin restart && echo "SARE 
rules updated."
  rc=$?
fi

case "$rc" in
0|1)
  rc=0
  ;;
esac
exit "$rc"




-- 
Take care,
Chris

Reply via email to