bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Revisiting Error handling (errexit)


From: Alex fxmbsw7 Ratchev
Subject: Re: Revisiting Error handling (errexit)
Date: Fri, 8 Jul 2022 12:28:06 +0200

On Fri, Jul 8, 2022, 12:23 Oğuz <oguzismailuysal@gmail.com> wrote:

> 8 Temmuz 2022 Cuma tarihinde Yair Lenga <yair.lenga@gmail.com> yazdı:
> >
> > Practical Example - real life. A job has to copy 3 critical data files.
> It
> > then sends notification via email (non-critical).
> >
> > #! /bin/bash
> > set -o errfail
> > function copy-files {
> >      # ALL files are critical, script will not cont
> >      cp /new/file1 /production/path/
> >      cp /new/file2 /production/path/
> >      # Use the files for something - e.g., count the lines.
> >      important-job /production/path/file1 /production/path/file2
> >
> >      ls -l /production/path | mail -s "all-good" notify@company.com ||
> > true    # Not critical
>

small side note there, a || true is big slow imho

> }
> >
> > if copy-files ; then
> >      more-critical-jobs
> >       echo "ALL GOOD"
> > else
> >       mail -s "PROBLEM" norify@company.com < /dev/null
> > fi
> >
> > What is the difference ? consider the case where /new/file1 does not
> > exists, which is critical error.
> > * Without errfail, an error message will be sent to script stderr, but
> the
> > script will continue to copy the 2nd file, and to perform the
> > important-job, even though the data is not ready.
>
>
> How is this any better than doing `cp ... && cp ... && important-job ...'?
>
>
> --
> Oğuz
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]