Use the :class:`~airflow.operators.bash_operator.BashOperator` to execute commands in a Bash shell.
.. exampleinclude:: ../../../airflow/example_dags/example_bash_operator.py :language: python :start-after: [START howto_operator_bash] :end-before: [END howto_operator_bash]
You can use :ref:`Jinja templates <jinja-templating>` to parameterize the
bash_command
argument.
.. exampleinclude:: ../../../airflow/example_dags/example_bash_operator.py :language: python :start-after: [START howto_operator_bash_template] :end-before: [END howto_operator_bash_template]
Add a space after the script name when directly calling a Bash script with
the bash_command
argument. This is because Airflow tries to apply a Jinja
template to it, which will fail.
t2 = BashOperator(
task_id='bash_example',
# This fails with 'Jinja template not found' error
# bash_command="/home/batcher/test.sh",
# This works (has a space after)
bash_command="/home/batcher/test.sh ",
dag=dag)