Shell loops process daily data in Linux

Source: Internet
Author: User

A date loop that is useful in processing some data that is stored by date. Especially testing and recording, deleting, reprocessing data. However, if you encounter a situation such as the span of a month, simply using a numerical cycle is not possible.
This shell can be used to handle the data for a number of days.

The code is as follows Copy Code

#!/usr/bin/env Bash
#author: Andy Zhou
#Date: 2013.8.6

SOURCE dateutil.sh
begin=20130701
end=20130904

For ((d= $begin; d<= $end; d= ' Getnextday $d ')); Todo
echo "Date:" $d
#. myshell.sh $d

Date Tool dateutil.sh:

The code is as follows Copy Code

#/usr/bin/env bash
#author: Andy Zhou
#date: 2013.8.2
Getnextday ()
{
    #date-D " 2013-09-10 +1 Day "+%y-%m-%d
    date-d" $ +1 Day "+%y%m%d
}
Getyearmonth ()
{
  ;   Date +%y%m--date=$1 #shortdate
}
Getday ()
{
    date +%d--date=$1 #shortdat E
}

Long_date ()
{
    date +%y-%m-%d--date=$1 #shortdate
}
Short_date ()
{
 & nbsp;  Date +%y%m%d--date=$1 #longdate
}
Long_yesterday ()
{
     date--date= ' 1 day ago ' +%y-%m-%d
}
Yesterday ()
{
     date--date= ' 1 day ago ' +%y%m%d
}
Lo Ng_today ()
{
    date +%y-%m-%d
}
Today ()
{
    date +%y%m%d
}< br> Now ()
{
    date ' +%y-%m-%d%h:%m:%s '
}
Last_month ()
{
    date --date= ' 1 month ago ' +%y%m '
}
Year ()
{
     date +%y
}
Month ()
{
&nb sp;   date +%m
}
Sec2date ()
{
     date-d "1970-01-01 UTC $ Seconds" "+%y% m%d '
}
Sec2datetime ()
{
     date-d "1970-01-01 UTC $ Seconds" "+%y%m%d%h:%m:%s"
}

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.