Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 巴什多恩';t运行bash文件_Python_Airflow - Fatal编程技术网

Python 巴什多恩';t运行bash文件

Python 巴什多恩';t运行bash文件,python,airflow,Python,Airflow,我刚开始使用apache airflow。我正在尝试从airflow运行test.sh文件,但无法运行 下面是我的代码,文件名是test.py import os from airflow import DAG from airflow.operators.bash_operator import BashOperator from datetime import datetime, timedelta default_args = { 'owner': 'airflow',

我刚开始使用apache airflow。我正在尝试从airflow运行test.sh文件,但无法运行

下面是我的代码,文件名是test.py

import os
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta


default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2015, 6, 1),
    'email': ['airflow@airflow.com'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
    # 'queue': 'bash_queue',
    # 'pool': 'backfill',
    # 'priority_weight': 10,
    # 'end_date': datetime(2016, 1, 1),
}

dag = DAG('test', default_args=default_args)

# t1 and t2 are examples of tasks created by instantiating operators
t1 = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag)

create_command = "sh home/ubuntu/test/inst/scripts/test.sh"

if os.path.exists(create_command):
   t2 = BashOperator(
        task_id= 'cllTest',
        bash_command=create_command,
        dag=dag
   )
else:
    raise Exception("Cannot locate {}".format(create_command))

t2.set_upstream(t1)
当我运行python~/aiffort/dags/test.py时,它不会抛出任何错误

但是,当我运行airflow list_dag时,它会抛出以下错误:

[2017-02-15 20:20:02,741] {__init__.py:36} INFO - Using executor SequentialExecutor
[2017-02-15 20:20:03,070] {models.py:154} INFO - Filling up the DagBag from /home/ubuntu/airflow/dags
[2017-02-15 20:20:03,135] {models.py:2040} ERROR - sh home/ubuntu/test/inst/scripts/test.sh
Traceback (most recent call last):
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/airflow/models.py", line 2038, in resolve_template_files
    setattr(self, attr, env.loader.get_source(env, content)[0])
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/jinja2/loaders.py", line 187, in get_source
    raise TemplateNotFound(template)
TemplateNotFound: sh home/ubuntu/test/inst/scripts/test.sh
我试着用它来回答,它不起作用


我在哪里犯错

尝试不使用“sh”,只需将命令设置为“home/ubuntu/test/inst/scripts/test.sh”

只使用脚本路径,不使用“sh”: create_command=“/home/ubuntu/test/inst/scripts/test.sh”


还要确保“airflow”用户具有执行“test.sh”脚本的权限

在.sh之后添加空格应该可以 这一点在《气流》一书中有所提及

t2 = BashOperator(
task_id='sleep',
bash_command="/home/batcher/test.sh", // This fails with `Jinja template not found` error
#bash_command="/home/batcher/test.sh ", // This works (has a space after)
dag=dag)