Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement a Shell script to traverse a date range

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to implement Shell script traversal of a date range", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "how to implement Shell script traversal of a date range"!

The code is as follows:

#!/ usr/bin/env bash

date1="$1"

date2="$2"

echo "date1: $date1"

echo "date2: $date2"

tempdate=`date -d "-0 day $date1" +%F`

enddate=`date -d "-0 day $date2" +%F`

tempdateSec=`date -d "-0 day $date1" +%s`

enddateSec=`date -d "-0 day $date2" +%s`

echo "####################################"

echo 'tempdate: '$tempdate

echo 'enddate: '$enddate

#for i in `seq 1 130`; do

for i in `seq 1 300`; do

if [[ $tempdateSec -lt $enddateSec ]]; then

break

fi

echo $tempdate

python pc_jibzhuanti_url.py $tempdate

tempdate=`date -d "-$i day $date1" +%F`

tempdateSec=`date -d "-$i day $date1" +%s`

done

This is a script that outputs time in reverse order. You need to input two time parameters, one is the start time and the other is the end time. For example, input:

The code is as follows:

./ pc_jibzhuanti_url_run.sh 2014-06-30 2014-06-01

The output is:

The code is as follows:

date1: 2014-06-30

date2: 2014-06-01

####################################

tempdate: 2014-06-30

enddate: 2014-06-01

2014-06-30

2014-06-29

2014-06-28

2014-06-27

2014-06-26

2014-06-25

2014-06-24

2014-06-23

2014-06-22

2014-06-21

2014-06-20

2014-06-19

2014-06-18

2014-06-17

2014-06-16

2014-06-15

2014-06-14

2014-06-13

2014-06-12

2014-06-11

2014-06-10

2014-06-09

2014-06-08

2014-06-07

2014-06-06

2014-06-05

2014-06-04

2014-06-03

2014-06-02

2014-06-01

At this point, I believe that everyone has a deeper understanding of "how to implement Shell script traversal of a date range," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report