Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I hope you see this reply, I am sorry for it being so late:

Do you have a link to a good explanation of why you'd set those? The "set -e" seems to indicate that the script would fail immediately if the borg backup job fails, which would prevent the Zabbix "send" command from alerting the monitoring system.

Thank you for your feedback, it's given me more to learn and think about!



There are quite a few examples around, just google the parameters 'set euo pipefail' (first hit [0])

you're right that just putting the set options on top of your file would be a bad idea. you need to write your script to actually account for these errors, making possible exitcodes entirely transparent

    1 #!/bin/bash
    2
    3 set -euo pipefail
    4 if ${DEBUG:-false}; then set -x; fi
    5
    6 function random_exitcode(){
    7         return $(( RANDOM % 5))
    8 }
    9
   10 function handle_error(){
   11   case "$?" in
   12     1)  echo "handling exitcode 1!";;
   13     2)  echo "handling exitcode 2!!";;
   14     3)  echo "handling exitcode 3!!!";;
   15     *)  echo "encountered unexpected exitcode: $?"; exit 2;;
   16   esac
   17 }
   18
   19 random_exitcode || handle_error
or, if you don't like functions:

  random_exitcode || LAST_EXITCODE=$?
  case "${LAST_EXITCODE:=0}" in ...

[0] https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-e...


Many thanks, I very much appreciate the effort you put into your reply, and your followup.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: