Shell extracts date log files

Source: Internet
Author: User

Introduction:

In the production environment, the application service generates fixed log files by date every day. Developers often need O & M personnel to provide these application logs, sometimes for a single day, sometimes for a period of time, there are a lot of repetitive and tedious work. To simplify the operation steps, I wrote a small script to retrieve the log file.

Analysis:

The log generation path is fixed.

Enter the start time and End Time on the keyboard to obtain and list all objects.

Pack the list file.

Upload the package file to ftp and download and view it through ftp.

#! /Bin/bash # obtain the log start time and end time to be packaged, and list all the files in between read-p "Enter the start time: "Startdateread-p" Enter the end time: "Senddatedate1 =$ (date-d $ Startdate" + % s ") date2 = $ (date-d $ Senddate "+ % s") date_count = $ (echo "$ date2-$ date1" | bc) day_m = $ (echo "$ date_count"/86400 | bc) for (sdate = 0; sdate <"$ day_m"; sdate ++ )) do tmp = $ (date-d "$ Startdate $ sdate days" "+ % F") tmp = report $ tmp. log. old logfiles = "$ logfiles $ tmp" done # define the path of log file generation file_dir =/var/w Ww/apps/ewp/logdate = 'date + % Y % m % d _ % H % m' cd $ file_dir # package tar-zcvf logs hostname..tar.gz $ logfiles # ftp upload Ftp_Server_Dir =$ (date + % Y % m % d) ftpaddr = "10.172.172.11" ftpuser = "ftpbuser" ftppass = "ftppass" ftp-n <! Open $ ftpaddruser $ ftpuser $ ftppassbinary # hashcd deploycd zfcd logmkdir $ Ftp_Server_Dircd $ Ftp_Server_Dirput without hostname..tar.gz closebye! # Delete the packaging file or back up the packaging file rm-rf ‑hostname..tar.gz



This article from the "Flying birds wings" blog, please be sure to keep this http://haolulu.blog.51cto.com/3164472/1229476

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.