Kann eine While Schleife trotz Exit 2 weiterlaufen?

Binfort

Well-Known Member
Moin Leute!

Die SSL Verschlüsselung mehrerer vHosts in unterschiedlichen Jails realisiere ich mit Let's Encrypt.

Bislang lief alles reibungslos, aber nach dem Update/Switch auf acme-client stehe ich vor einem kleinen Problem:

Falls die Zertifikate noch ausreichend gültig sind, endet acme-client lt. Manpage mit einem Exit Status 2.

Genau solang brauchte ich in Stunden um den Fehler zu finden, die While Schleife zum Erneuern der Zertifikate bricht nach dem erste Exit 2 ab.

Kann ich den Exit Status irgendwie abfangen od. wäre es schlau bzw. hilfreich den Programmaufruf in eine if zu packen?

Danke für eure Hilfe.
 
Ups, ein Auszug aus dem Shellscript, das Variablendeklarierungsgedöns erspare ich euch:
Code:
#!/bin/sh
for JAIL in ${TARGETS}; do
  CHALLENGEDIR="/data/j/${JAIL}/usr/local/www/.well-known/acme-challenge"
  cat "${BASEDIR}/domains/${JAIL}.txt" | while read DOMAIN LINE ; do
    acme-client -v -C "${CHALLENGEDIR}" \
                -k "${SSLDIR}/private/${DOMAIN}.pem" \
                -c "${CERTSDIR}" \
                ${DOMAIN} ${LINE}
    echo $DOMAIN" done!"
  done
done
Der acme-client endet beim ersten Aufruf mit Status 2. Das echo danach und die weiteren Loops werden nicht mehr ausgeführt da die Schleife endet.
 
Nein, ein non-zero exit beendet kein shell script, es sei denn, du hast set -e aktiv.

Code:
  -e  Errexit.  Exit the shell immediately should an error occur or a
      command fail.  For pipelines and && and || constructs, only exit
      if the last component fails.  Errexit is ignored for while,
      until, if, and elif lists and pipelines beginning `!'.
 
@TCM Was soll ich sagen... "set -e" ist tatsächlich aktiv. Oh Mann :( das hatte ich die ganze Zeit übersehen und obendrein unterschlagen.

Hab es entfernt und jetzt klappt alles wie gehabt.

Der Vollständigkeit halber der Auszug aus "man sh":

-e errexit
Exit immediately if any untested command fails in non-interactive
mode. The exit status of a command is considered to be
explicitly tested if the command is part of the list used to
control an if, elif, while, or until; if the command is the left
hand operand of an ``&&'' or ``||'' operator; or if the command
is a pipeline preceded by the ! keyword. If a shell function is
executed and its exit status is explicitly tested, all commands
of the function are considered to be tested as well.

It is recommended to check for failures explicitly instead of
relying on -e because it tends to behave in unexpected ways,
particularly in larger scripts.
 
Unabhängig von den anderen Lösungen hat Binfort etwas versteckt eine zusätzliche Lösung genannt, die auch mit "-e" funktioniert:
Code:
acme-client argumente || true
Damit ist der Exit-Status auf jeden Fall null.
 
Zurück
Oben