now is better than never

[airflow] 외부 쉘 스크립트 수행 본문

데이터 엔지니어링/airflow

[airflow] 외부 쉘 스크립트 수행

김초송 2023. 6. 18. 19:44

쉘 스크립트

  • Unix/Linux Shell 명령을 이용하여 만들어지고 인터프리터에 의해 한 줄씩 처리되는 파일
  • Echo, mkdir, cd, cp, tar, touch 등의 기본적인 쉘 명령어를 입력하여 작성
  • 변수를 입력받거나 For , if 문 그리고 함수도 사용 가능
  1. 쉘 명령어를 이용하여 복잡한 로직을 처리
  2. 쉘 명령어 재사용

 

  • plugins : 커스터마이징한 py, sh 파일을 컨테이너와 연동
  • 노란색 박스 /plugins 를 쉘 스크립트 파일이 있는 디렉토리로 변경

 

from airflow import DAG
import pendulum
from airflow.operators.bash import BashOperator

with DAG(
    dag_id="dags_bash_select_fruit",
    schedule="10 0 * * 6#1",
    start_date=pendulum.datetime(2023, 6, 1, tz="Asia/Seoul"),
    catchup=False
) as dag:
    
    t1_orange = BashOperator(
        task_id="t1_orange",
        bash_command="opt/airflow/plugins/shell/select_fruit.sh ORANGE",
    )

    t2_avocado = BashOperator(
        task_id="t2_avocado",
        bash_command="opt/airflow/plugins/shell/select_fruit.sh AVOCADO",
    )

    t1_orange >> t2_avocado

 

  • 강제로 DAG 실행

'데이터 엔지니어링 > airflow' 카테고리의 다른 글

[airflow] Python Operator  (2) 2023.06.22
[airflow] Email Operator  (1) 2023.06.19
[airflow] CRON 스케쥴  (0) 2023.06.17
[airflow] DAG 생성 (bash)  (0) 2023.06.16
Airflow 개념  (0) 2023.06.14