runuser inside some of our deployment scripts. In looking at the scripts I'm wondering how the error handling would work if any of the commands within the
runuser steps errors out. In attempting to solve this myself, I haven't come up with any definitive other than using
&& as such:
#!/bin/bash -e echo "- next" # this is what we're currently doing, which appears to not handle errors runuser -l $USER -c "echo cmd2; ls non-existant-file; echo done"; echo " exit code $?" echo "- next2" # best solution I've come up with so far runuser -l $USER -c "echo cmd2 && ls non-existant-file && echo done"; echo " exit code $?" echo "- finish"
Any suggestions for how to better address this issue? Given some of the individual commands within the
runuser script can get pretty involved (i.e. conditionals and the like), I'm hoping to find a more-elegant/obvious way to handle any errors.
Another thought is to do something like this:
runuser -l $USER -c "echo cmd2 && ls non-existant-file && echo done" || exit 1