How to run bash script file in Airflow

前端 未结 1 515
故里飘歌
故里飘歌 2020-12-14 02:55

I have a bash script that creates a file (if it does not exist) that I want to run in Airflow, but when I try it fails. How do I do this?

#!/bin/bash
#create         


        
1条回答
  •  心在旅途
    2020-12-14 03:15

    From the tutorial this is OK:

    t2 = BashOperator(
        task_id='sleep',
        bash_command='sleep 5',
        retries=3,
        dag=dag)
    

    But you're passing a multi-line command to it

    create_command = """
     ./scripts/create_file.sh
    """
    

    should be

    create_command = "./scripts/create_file.sh "
    

    Moreover, you also have to make sure that you are in the correct directory to avoid cryptic errors. Do it like this for example:

    create_command = "./scripts/create_file.sh"
    if os.path.exists(create_command):
       t1 = BashOperator(
            task_id= 'create_file',
            bash_command=create_command,
            dag=dag
       )
    else:
        raise Exception("Cannot locate {}".format(create_command))
    

    0 讨论(0)
提交回复
热议问题