Shell scripts traverse a date range instance _linux shell

Source: Internet
Author: User
Tags date1

If you're dealing with a shell script and it's a common thing to traverse a time range, share it with you today:

Copy Code code as follows:

#!/usr/bin/env Bash
Date1= "$"
Date2= "$"

echo "Date1: $date 1"
echo "Date2: $date 2"

Tempdate= ' date-d '-0 day $date 1 "+%f"
Enddate= ' date-d '-0 day $date 2 "+%f"
Tempdatesec= ' date-d '-0 day $date 1 "+%s"
Enddatesec= ' date-d '-0 day $date 2 "+%s"

echo "####################################"
Echo ' tempdate: ' $tempdate
Echo ' EndDate: ' $enddate

#for i in ' seq 1 130 '; Todo
For i in ' SEQ 1 300 '; Todo
if [[$tempdateSec-lt $enddateSec]]; Then
Break
Fi

Echo $tempdate
Python pc_jibzhuanti_url.py $tempdate
Tempdate= ' date-d '-$i day $date 1 "+%f"
Tempdatesec= ' date-d '-$i day $date 1 "+%s"
Done

This is a reverse output time script, you need to enter two time parameters, one is the start time, one is the end time, such as input:

Copy Code code as follows:

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

The result of the output is:
Copy Code code 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

OK, take care of!!!!.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.