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