Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 2.05 KB

bash.rst

File metadata and controls

64 lines (46 loc) · 2.05 KB

BashOperator

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]

Templating

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]

Troubleshooting

Jinja template not found

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)