Infra/Linux

bash shell 로 날짜별 script 수행해보기

Tomining 2018. 1. 23. 10:27
START_YMD ~ END_YMD 까지 일자별 script 수행


#! /bin/bash

START_YMD=$(date -d $1 +"%Y%m%d")
END_YMD=$(date -d $2 +"%Y%m%d")
END_YMD_S=$(date -d $2 +"%s")

echo "startDate: $START_YMD"
echo "endDate: $END_YMD"

if [ $START_YMD -ge $END_YMD ];
then
        echo "start ~ from parameter are invalid."
fi

CURRENT="$START_YMD"
CURRENT_S=$(date -d $CURRENT +"%s")

while [ $CURRENT_S -le $END_YMD_S  ];
do
        echo $CURRENT
        # run shell

        CURRENT=`date -d "$CURRENT 1 day" +"%Y%m%d"`
        CURRENT_S=`date -d "$CURRENT" +"%s"`
done