Example of logging script error, e.g. cron job Simulate output to stderr with exit code 1 and write stderr to fail.log. Then proccess file as you want, e.g. send message to slack. (echo "Test error" >&2; exit 1) 2>>/tmp/fail.log || cat /tmp/fail.log