Linux shell script executes commands in cycles according to date and generates file names

Date-related commands date

date常用命令
#当前日期和时间:年月日 时分秒(24小时)
today=date +"%Y-%m-%d_%H:%M:%S"
#依据当前日期和差值计算新日期
yesterday=date -d "-1 day" +"%Y-%m-%d"
#依据指定日期start_date和差值计算新日期
end_date=date -d "${start_date} -3 day" +"%Y-%m-%d"

In the shell script, the file names related to the date are generated in sequence according to the date

start_date="20200601"
end_date="20200630"

#从start_date到end_date,包含前后两端点
while ["${start_date}" -le "${end_date}"];
do
    python3 ./test.py ${start_date} > ./out_${start_date}.txt 2>&1
    start_date=$(date -d "${start_date} +1 days" +%Y%m%d)
done

Attached to the basics of Linux-shell script (variable definition, variable type, variable operation)

附date --help

附date format

 

 

 

 

Guess you like

Origin blog.csdn.net/authorized_keys/article/details/107063319