bug-bash
[Top][All Lists]
Advanced

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

Re: Revisiting Error handling (errexit)


From: Oğuz
Subject: Re: Revisiting Error handling (errexit)
Date: Fri, 8 Jul 2022 13:22:46 +0300

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
> }
>
> 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]