posted by 귀염둥이채원 2021. 4. 22. 19:44

시작날짜, 종료날짜를 입력해서 매주 일요일, 화요일만 수행하는 스크립트 샘플입니다.

 

CLUSTER_ID="5FFZMTA6C"
BATCH_START_DATE="20210228"
BATCH_END_DATE="20210420"

while true; do
  if [ $BATCH_START_DATE -gt $BATCH_END_DATE ]; then
      exit 0
  fi

  day_of_week=$(date -d "${BATCH_START_DATE}" "+%A")
  if [ $day_of_week == "Sunday" ] || [ $day_of_week == "Tuesday" ]; then
    DISP_START_DATE=$(date -d "${BATCH_START_DATE} +1days" "+%Y%m%d")
    DISP_END_DATE=$(date -d "${BATCH_START_DATE} +7days" "+%Y%m%d")
    echo "BATCH: $BATCH_START_DATE"
    echo "./backfill.sh $_CLUSTER_ID stat $DISP_START_DATE $DISP_END_DATE;"
  fi

  sleep 0.1
  BATCH_START_DATE=$(date -d "${BATCH_START_DATE} +1days" "+%Y%m%d")
done

 

$ bash test7.sh | grep backfill
./backfill.sh  stat 20210301 20210307;
./backfill.sh  stat 20210303 20210309;
./backfill.sh  stat 20210308 20210314;
./backfill.sh  stat 20210310 20210316;
./backfill.sh  stat 20210315 20210321;
./backfill.sh  stat 20210317 20210323;
./backfill.sh  stat 20210322 20210328;
./backfill.sh  stat 20210324 20210330;
./backfill.sh  stat 20210329 20210404;
./backfill.sh  stat 20210331 20210406;
./backfill.sh  stat 20210405 20210411;
./backfill.sh  stat 20210407 20210413;
./backfill.sh  stat 20210412 20210418;
./backfill.sh  stat 20210414 20210420;
./backfill.sh  stat 20210419 20210425;
./backfill.sh  stat 20210421 20210427;​