Linux Shell Date loops by Time fragment

Source: Internet
Author: User

Remember that once wrote the script by the days of the cycle, the real date can be any day, like this:

1start_day=$ (Date-D"$TODAY -1days"+%y%m%d);2 3end_day=$ (Date-D"$TODAY-${cycle}days"+%y%m%d);4 5  for((; $END _day<= $START _day; end_day=$ (Date-D"$END _day +1days"+%y%m%d )))6 7  Do8 9 ... ..Ten  One  Done
$TODAY is the time parameter, such as 20141222, which is passed by the outside world;
Cycle is an integer that represents the number of days you want the loop to be, such as one months 30.
And then cycle the time to end_day each additional day, add enough 30 times, the loop terminates.

Now it suddenly takes 10 minutes to cycle through the fragments.
The thought of ' date-d ' 201412021311 +10minutes "+%h:%m ' such a way can be effective, but found that such a write. Try it, write like this.
' date-d ' 20141202 1311 +10minutes "+%h:%m" to work, it feels so wonderful ...

Changed it, only in a day to cycle
1Startpoint=0000;2Endpoint=0010;3 4  for((i=1; i<=144; i++))5  Do6Startpoint_format= 'Date-D"$startpoint"+%h:%M; '7Endpoint_format= 'Date-D"$endpoint"+%h:%M; '8 ...9Startpoint= 'Date-D"$startpoint +10minutes"+%h%M; 'TenEndpoint= 'Date-D"$endpoint +10minutes"+%h%M; ' One  Done

This looks pretty good:)

You can also follow the time stamp increase or decrease to do the cycle, without this look comfortable:)

Linux Shell Date loops by Time fragment

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.