0
0
Apache Airflowdevops~5 mins

BashOperator for shell commands in Apache Airflow - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the BashOperator in Airflow?
The BashOperator allows you to run shell commands or scripts as tasks within an Airflow workflow (DAG). It helps automate command-line operations.
Click to reveal answer
beginner
How do you specify the shell command to run in a BashOperator?
You use the 'bash_command' parameter to provide the shell command or script you want to execute.
Click to reveal answer
intermediate
What happens if the shell command run by BashOperator fails?
If the shell command exits with a non-zero status, the BashOperator marks the task as failed, which can trigger retries or alerts.
Click to reveal answer
intermediate
Can BashOperator run multi-line shell scripts?
Yes, you can pass multi-line shell scripts using triple quotes or by referencing a script file in the 'bash_command' parameter.
Click to reveal answer
intermediate
How do you pass parameters or variables to a BashOperator command?
You can use Jinja templating in the 'bash_command' to insert variables dynamically, like '{{ ds }}' for the execution date.
Click to reveal answer
Which parameter do you use to define the shell command in BashOperator?
Acommand
Bscript_path
Cshell_script
Dbash_command
What does BashOperator do if the shell command exits with a non-zero status?
AMarks the task as failed
BIgnores the error and continues
CAutomatically retries without limit
DRestarts the entire DAG
Can you use Jinja templating inside the bash_command parameter?
AOnly in Airflow 1.x versions
BYes, to insert dynamic variables
COnly for PythonOperators
DNo, only static commands allowed
How can you run a multi-line shell script with BashOperator?
AUse triple quotes or reference a script file
BOnly single-line commands are allowed
CUse PythonOperator instead
DMulti-line scripts are not supported
What is a common use case for BashOperator?
AManaging database connections
BCreating Python functions
CRunning shell commands or scripts as tasks
DScheduling DAGs
Explain how to use BashOperator to run a shell command in an Airflow DAG.
Think about how you tell Airflow what shell command to run and what happens if it fails.
You got /4 concepts.
    Describe how you can pass dynamic values like execution date into a BashOperator command.
    Remember Airflow supports templates inside bash_command.
    You got /3 concepts.