Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

How to run a shell script with parameters using airflow's SSH operator

I'm trying to run a Pentaho job in a remote system using airflow. I was able to use airflow's SSH operator to SSH into remote system and run the shell script but I'm wondering how to pass parameters to the shell script.

For example the shell command looks like

sh -C "$PENT_HOME"/kitchen.sh -file="$PENT_HOME/Details.kjb" -level=Basic > $logFolder/date -u +"%Y-%m-%dT%H:%M:%SZ"-Details.log 2>&1

My DAG script for running a simple shell script without parameters is

t1 = SSHOperator(ssh_conn_id='SSH-dev',
    task_id='ssh_operator',
    command='/opt/scripts/test.sh ',
    dag=dag)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

command argument takes any bash/shell command, so you can do this for example:

t1 = SSHOperator(ssh_conn_id='SSH-dev',
    task_id='ssh_operator',
    command='/opt/scripts/test.sh arg1 arg2',
    dag=dag)

In your case:

t1 = SSHOperator(ssh_conn_id='SSH-dev',
    task_id='ssh_operator',
    command='bash "$PENT_HOME"/kitchen.sh -file="$PENT_HOME/Details.kjb" -level=Basic > $logFolder/date -u +"%Y-%m-%dT%H:%M:%SZ"-Details.log 2>&1',
    dag=dag)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...