Shell traversal of a date range

Source: Internet
Author: User
Tags date1

If you're dealing with shell scripts and traversing a time frame is a common thing, let's share with you today:

#!/usr/bin/env bashdate1= "$" 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: ' $tempdateecho ' enddate: ' $enddate #for i in ' seq 1 130 '; Dofor i in ' SEQ 1 300 '; Do  if [[$tempdateSec-lt $enddateSec]] and 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:

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

The result of the output is:

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, done!!!

Shell traversal of a date range

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.