Reputation: 2977
I'm trying to raise an error with Bash, in a block that's wrapped inside of a Python Airflow script.
export PATH=/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
export rundate=`TZ='America/Los_Angeles' date +%F -d "yesterday"`
export AWS_CONFIG_FILE="/home/ubuntu/.aws/config"
thisshouldnotrun
/home/ubuntu/bin/snowsql -f //home/ubuntu/script/dev/sql1.sql 1> /home/ubuntu/logs/"$rundate"_dev.log 2> /home/ubuntu/logs/"$rundate"_error_dev.log
Basically, that last line that calls the snowsql
function will always return an exit status of 0, even when I remove the pieces of redirection. So that's why I'm redirecting to that error_dev.log file.
Basically, I want to add an if
block and within it, manually raise an error if a file exists. I've tried adding exit 64
but Airflow doesn't seem to like that. Is using exit ##
the easiest to raise an error in Bash? Not sure what Airflow is even expecting to be quite honest.
Upvotes: 0
Views: 557
Reputation: 39
If you exit
with anything other than 0
it is considered an error code in bash.
There are several different exit codes that are returned when SnowSQL quits/exits:
0: Everything ran smoothly.
1: Something went wrong with the client.
2: Something went wrong with the command line arguments.
3: SnowSQL could not contact the server.
4: SnowSQL could not communicate properly with the server.
5: The exit_on_error configuration option was set and SnowSQL exited because of an error.
In the case of checking for a file's existence, you can use:
[[ -f <file> ]] && <on success> || <on failure> (exit 64, or w/e)
Upvotes: 2