我有一个bash脚本,它创建了一个我想在Airflow中运行的文件(如果它不存在),但是当我尝试它失败时。我该怎么做?
echo "<td>""<a href='product_description.php?id='>" . $row['PropertyType'] . "</a></td>";
以下是我在Airflow中调用它的方式:
#!/bin/bash
#create_file.sh
file=filename.txt
if [ ! -e "$file" ] ; then
touch "$file"
fi
if [ ! -w "$file" ] ; then
echo cannot write to $file
exit 1
fi
答案 0 :(得分:13)
从教程中可以这样:
t2 = BashOperator(
task_id='sleep',
bash_command='sleep 5',
retries=3,
dag=dag)
但是你正在向它传递一个多行命令
create_command = """
./scripts/create_file.sh
"""
应该是
create_command = "./scripts/create_file.sh"
此外,您还必须确保您位于正确的目录中以避免出现神秘错误。这样做是这样的:
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))
答案 1 :(得分:1)
t2 = BashOperator(
task_id='bash_example',
# "scripts" folder is under "/usr/local/airflow/dags"
bash_command="scripts/test.sh",
dag=dag)