From caa045c368d1087cdddd3d6b5bab3766c76f32ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 1 Feb 2021 15:05:57 +0800 Subject: [PATCH] Initial commit. --- AUTHORS | 1 + AUTHORS.zh-cn | 1 + AUTHORS.zh-tw | 1 + Build.PL | 78 ++ COPYING | 674 +++++++++++ Changes | 785 ++++++++++++ INSTALL | 211 ++++ INSTALL.zh-cn | 186 +++ INSTALL.zh-tw | 186 +++ MANIFEST | 39 + META.yml | 14 + Makefile.PL | 91 ++ NEWS | 29 + README | 67 ++ README.zh-cn | 58 + README.zh-tw | 58 + SIGNATURE | 61 + THANKS | 2 + THANKS.zh-cn | 1 + THANKS.zh-tw | 1 + TODO | 2 + TODO.zh-cn | 1 + TODO.zh-tw | 1 + UPGRADE | 47 + UPGRADE.zh-cn | 39 + UPGRADE.zh-tw | 39 + arclog | 2884 +++++++++++++++++++++++++++++++++++++++++++++ arclog.en.html | 506 ++++++++ arclog.zh-cn.html | 510 ++++++++ arclog.zh-tw.html | 515 ++++++++ fdl.txt | 397 +++++++ pgpkey.asc | 40 + t/00-signature.t | 22 + t/01-exhaust.t | 145 +++ t/02-several.t | 266 +++++ t/03-fallback.t | 256 ++++ t/04-errors.t | 308 +++++ t/99-pod.t | 5 + t/_helper.pm | 1178 ++++++++++++++++++ 39 files changed, 9705 insertions(+) create mode 100644 AUTHORS create mode 100644 AUTHORS.zh-cn create mode 100644 AUTHORS.zh-tw create mode 100755 Build.PL create mode 100644 COPYING create mode 100644 Changes create mode 100644 INSTALL create mode 100644 INSTALL.zh-cn create mode 100644 INSTALL.zh-tw create mode 100644 MANIFEST create mode 100644 META.yml create mode 100755 Makefile.PL create mode 100644 NEWS create mode 100644 README create mode 100644 README.zh-cn create mode 100644 README.zh-tw create mode 100644 SIGNATURE create mode 100644 THANKS create mode 100644 THANKS.zh-cn create mode 100644 THANKS.zh-tw create mode 100644 TODO create mode 100644 TODO.zh-cn create mode 100644 TODO.zh-tw create mode 100644 UPGRADE create mode 100644 UPGRADE.zh-cn create mode 100644 UPGRADE.zh-tw create mode 100755 arclog create mode 100644 arclog.en.html create mode 100644 arclog.zh-cn.html create mode 100644 arclog.zh-tw.html create mode 100644 fdl.txt create mode 100644 pgpkey.asc create mode 100755 t/00-signature.t create mode 100755 t/01-exhaust.t create mode 100755 t/02-several.t create mode 100755 t/03-fallback.t create mode 100755 t/04-errors.t create mode 100755 t/99-pod.t create mode 100644 t/_helper.pm diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..d6c1a2a --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +imacat diff --git a/AUTHORS.zh-cn b/AUTHORS.zh-cn new file mode 100644 index 0000000..2e02909 --- /dev/null +++ b/AUTHORS.zh-cn @@ -0,0 +1 @@ +ÒÀÂêè diff --git a/AUTHORS.zh-tw b/AUTHORS.zh-tw new file mode 100644 index 0000000..2ec7e15 --- /dev/null +++ b/AUTHORS.zh-tw @@ -0,0 +1 @@ +¨Ìº¿¿ß diff --git a/Build.PL b/Build.PL new file mode 100755 index 0000000..8c04682 --- /dev/null +++ b/Build.PL @@ -0,0 +1,78 @@ +#! /usr/bin/perl -w +# Build.PL: Installation configuration for Module::Build +use strict; +use warnings; +use Config qw(%Config); +use Module::Build; + +# Check if there is any old file +use vars qw(%old_version); +%old_version = qw(); +foreach (qw(/usr/sbin/arclog.pl + /usr/sbin/arclog + /usr/share/man/man8/arclog.pl.8 + /usr/share/man/man8/arclog.8 + /usr/local/sbin/arclog.pl + /usr/local/sbin/arclog + /usr/local/share/man/man8/arclog.pl.8 + /usr/local/share/man/man8/arclog.8)) { + $old_version{$_} = 1 if -e $_; +} +foreach my $cnf (qw(installman1dir installsiteman1dir installvendorman1dir + man1dir man1direxp siteman1dir siteman1direxp sysman + vendorman1dir vendorman1direxp)) { + next unless defined $Config{$cnf} && -d $Config{$cnf}; + $_ = $Config{$cnf}; + s/\/man1$/\/man8/; + $old_version{"$_/arclog.8"} = 1 if -e "$_/arclog.8"; + $old_version{"$_/arclog.pl.8"} = 1 if -e "$_/arclog.pl.8"; +} +foreach my $cnf (qw(installscript installsitescript installvendorscript + scriptdir scriptdirexp sitescript sitescriptexp + vendorscript vendorscriptexp + bin binexp installbin installsitebin installvendorbin + sitebin sitebinexp vendorbin vendorbinexp)) { + next unless defined $Config{$cnf} && -d $Config{$cnf}; + $_ = $Config{$cnf}; + s/\/bin$/\/sbin/; + $old_version{"$_/arclog"} = 1 if -e "$_/arclog"; + $old_version{"$_/arclog.pl"} = 1 if -e "$_/arclog.pl"; +} +if (keys %old_version > 0) { + $_ = join " ", sort keys %old_version; + warn << "EOT"; +-- Old Files Found +You may remove the following old files after "make install": + $_ +EOT +} + +my $build = Module::Build->new( + dist_name => "arclog", + dist_version_from => "arclog", + dist_abstract => "Archive log files monthly", + dist_author => "imacat ", + license => "gpl", + sign => 1, + + script_files => [ "arclog" ], + requires => { + "perl" => "5.8.0", + "Date::Parse" => 0, + }, + recommends => { + "File::MMagic" => 0, + "Compress::Zlib" => 0, + "Compress::Bzip2" => 2, + "Term::ReadKey" => 0, + }, + build_requires => { + "Module::Signature" => 0, + "Test::Pod" => 0, + }, + add_to_cleanup => [ "t/logs*" ], +); + +$build->create_build_script; + +__END__ diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Changes b/Changes new file mode 100644 index 0000000..8befd53 --- /dev/null +++ b/Changes @@ -0,0 +1,785 @@ +arclog change log + +2008-11-18 + 1. INSTALL and arclog.en.html: Fixed the grammer on + installation with the CPAN or CPANPLUS shell, changed + "install with the CPAN shell using" and "install with the + CPANPLUS shell using" to "install it with the CPAN shell + by running" and "install it with the CPANPLUS shell by + running". + 2. INSTALL* and ahping.*.html: Changed "Fedora/Red Hat" to + "Red Hat/Fedora/CentOS". + 3. INSTALL.zh-tw and INSTALL.zh-cn: Added the missing + Date::Parse to the required modules section. + +2008-11-17 + 1. INSTALL and arclog.en.html: Fixed the grammer on required + and optional module installation, changed "install using" + and "install this using" to "install it by running". + +2008-11-15 + 1. arclog.*.html: Clean-up some blank lines. + 2. arclog.en.html: Removed the message about CPAN source + in required modules. It is stated in the module + description in detail now. + 3. arclog.*.html: Fixed so that installation from source and + with shells are joint into one sentense. + +2008-11-12 + 1. INSTALL, arclog.en.html: Updated "don't" and "won't" to + "do not" and "will not". + 2. INSTALL, arclog.en.html: Updated "ActivePerl MS-Windows + users" to "ActivePerl users". ActivePerl use ppm + on all platforms, not limiting to MS-Windows. + 3. INSTALL: Updated "ActivePerl MS-Windows + users" to "ActivePerl users". ActivePerl use ppm + on all platforms, not limiting to MS-Windows. + 4. INSTALL*, arclog.*.html: Added the command lines to + install modules with the CPANPLUS shell. + +2008-11-11 + 1. INSTALL*, arclog.*.html: Updated information on + optional Perl modules, to describe different installation + commands for different operating systems. + 2. arclog: Fixed the _private::ProgressBar class so + that it does not use() Term::ReadKey, but require() it + at object initialization. This enables it to work + when Term::ReadKey is missing. + 3. arclog: Fixed the update() method of the + _private::ProgressBar class, to accept a dynamic label. + +2008-09-30 + 1. arclog: Update the update() method of the the + _private::ProgressBar class too use the bracket + characters instead of the pipe character for a better + visual outlook. + +2008-09-29 + 1. arclog: Use the _private::ProgressBar class in replace of + the show_progress() function to display the progress bar. + This makes the progress bar easier and more pretty. + +2008-04-21 + 1. INSTALL and arclog.en.html: Fixed typo: "instalation" to + "installation". + +2007-12-05 + 1. arclog: Initialize the static variables within BEGIN {...} + blocks for all _private::* classes. + 2. NEWS: Added. The NEWS file is quite useful in addition to + the Changes change log. + 3. arclog.*.html: Added GPLv3 license update to the 3.00 + release notes. + 4. arclog.*.html: Refer to NEWS instead of Changes for release + notes. + +2007-12-04 + 1. Makefile.PL: Fixed to prevent importing symbols when + checking optional prerequisites. + 2. arclog: Fixed the check_type() method of the + _private::LogFile class, so that empty files are checked + with the file name suffix, too. This solve the issue + that Compress::Bzip2 2 creates empty files which confuse + further processing on file name suffix stripping. + 3. arclog: Removed unused $GZIP_IO and $BZIP2_IO from the + _private::LogFile class. + +2007-12-03 + 1. arclog.zh-tw.html, arclog.zh-cn.html: "¤£»Ý­n¦w¸Ë·sª©" was + revised to "¤£»Ý­nª@¯Å·sª©". + 2. Build.PL: Fixed the comment. This file is "Build.PL", + not "Makefile.PL". + 3. Build.PL: Added "use warnings;". + +2007-12-03 version 3.04 + Documentation fix. + 1. arclog, arclog.*.html, README*: Added the information on + the usability of arclog with log files from many + softwares that log with an Apache-like log format. + 2. arclog.zh-cn.html: Fixed the version number. + 3. arclog.*.html: Added ... to the description. + +2007-12-03 version 3.03 + 1. t/*.t: Fixed so that send frread($fs) instead of $cs + is sent to arclog STDIN when reading from STDIN, so that + compresed content is sent to arclog but not the original + content. + 2. arclog.zh-tw.html, arclog.zh-cn.html: Revised the Chinese + text on "3-argument open()" so that it is more readable. + 3. t/_helper.pm: Updated the way we generate the time with + time zones in the mkrndlog_apache() and + mkrndlog_modfiso() subroutines, using "gmtime($t + $tz)", + so that we can obtain a reliable time text with time zone + without using time2str() from Date::Format + 4. t/04-errors.t: Added a test on "a same log file is + specified more than once". + +2007-12-02 + 1. t/02-several.t, t/03-fallback.t, t/04-errors.t: Use + "do { ... } until !... " instead of "do { ... } while ..." + so that the code is more readable. + 2. t/02-several.t, t/03-fallback.t, t/04-errors.t: Initialize + @cs and @cem before using them. + +2007-12-01 + 1. arclog: Use "use 5.008" instead of "use 5.8.0", for + compatibility with older Perl, and get ride of the warning + of Perl 5.10. + +2007-11-30 + 1. t/_helper.pm: Updated the version number to 0.02. + 2. arclog, arclog.*.html: Added NTP in addition to Syslog + to the note with log file formats without years. + 3. arclog.zh-tw.html, arclog.zh-cn.html: Fixed the text + on the note with log file formats without years. + 4. t/_helper.pm: Reorder the subroutines. + 5. t/_helper.pm: Reset the %WHEREIS hash in the beginning. + 6. t/01-exhaust.t: Fixed to set %cof to "" instead of 1 + when not creating existing files. + 7. t/_helper.pm: Removed unused "ce" from @KEEPTYPES. + +2007-11-30 version 3.02 + 1. t/_helper.pm: Use time2str() from Date::Format to + generate the time text instead of doing this my self. + The way I generate the time text cannot deal with + daylight saving time. It should be safe to use + Date::Format, since Date::Format is in the same TimeDate + distribution as Date::Parse, at least till now. + 2. t/_helper.pm: Increased time zone range from -1200 to + +1400 in the mkrandlog_apache() and mkrandlog_modfiso() + subroutines. + +2007-11-29 + 1. arclog.zh-tw.html, TODO.zh-tw, TODO.zh-cn: Changed + 'ÁcÅ餤¤å' to '¥¿Å餤¤å'. + +2007-11-28 version 3.01 + Test suite improvement. + 1. arclog, TODO.*: Clean up to-do list. + 2. Makefile.PL: Use "use 5.008" instead of "use 5.8.0" for + compatibility with older Perl. + 3. t/01-exhaust.t: Added $vardump to error output, to catch + CPAN testers test failurs. + 4. Return to build distribution with ExtUtils::MakeMaker, + since Module::Build did not preserve the original file + date. + +2007-11-28 version 3.00 + 1. t/01-exhaust.t: Fixed so that a zero-sized result file + is valid as application/x-bzip2. This is to fix the + issue that Compress::Bzip2 does not write anything if + no data is sent to the compression handler. + +2007-11-27 + 1. Makefile.PL, Build.PL: Clean-up old file found message. + 2. Makefile.PL: Added message for optional prerequisites. + 3. arclog.zh-tw.html, arclog.zh-cn.html: Tag the languages. + 4. t/02-several.t: Added the missing "several source files + all listed as arguments" tests. + 5. t/01-exhaust.t: Moved @OVERTYPES to t/_helper.t. + 6. t/02-several.t: Use random log format instead of Apache + access log. + 7. t/03-fallback.t: Added, to test the fall back behavior. + +2007-11-26 + 1. t/03-errors.t: Renamed to t/04-errors.t. + 2. t/01-exhaust.t: Moved @KEEPTYPES to t/_helper.t. + 3. t/04-errors.t: Fixed to set $num with rand(). + 4. t/_helper.pm, t/*.t: Updated the license to GPLv3. + 5. arclog.*.html: Added stylesheets and access guide. + 6. README, README.zh-tw, README.zh-cn: Updated. + 7. fdl.txt: Added. + 8. MSWin32 and MS-Win32 is now written as MS-Windows in the + documentation. + 9. arclog: Reorder the debug message in the check_gzip() and + check_bzip2() methods of the _private::IO class. + 10. Makefile.PL, Build.PL: Fixed comment typo. ("any old files") + 11. Build.PL: Added "recommends" and "build_requires". + +2007-11-25 + 1. t/03-errors.t: Fixed while loop to do...while loop when + obtaining output prefix, so that we obtain a random word first. + 2. t/03-errors.t: Renamed $output to $opref. Added $oprefb as + the base name of the output prefix. + 3. t/_helper.t: Fixed the errors in the mkrndlog_apache() and + mkrndlog_modfiso() subroutines that dump $tzoff as $zoff. + 4. t/_helper.t: Fixed the time zone representation that mistakenly + output -0030 as +0030 in the mkrndlog_apache() and + mkrndlog_modfiso() subroutines. This test suite bug is hard to + track, since it only appears with log formats with time zones, + in the time zone -0300 and log records in that one-hour + boundary. This chance is too small. I saw one or two every + now and then, and am pretty sure there is a bug, but spent + numerous time testing in vain. I finally got this bug. Yes! + 5. t/_helper.t: Fixed the $tzoff calculation from + timegm(@_[0...5]) - timelocal(@_[0...5]) to + timelocal(localtime) - timelocal(gmtime) in the + mkrndlog_apache() and mkrndlog_modfiso() subroutines. + 6. t/_helper.t: Set time to 00:00:00 in the monrng_rand() + subroutine. + 7. t/02-several.t: Added, to test archiving several log files + at once. + 8. arclog, arclog.en.html, INSTALL: Fixed the typo "archieve" + as "archive". + 9. t/01-exhaust.t: Moved @SRCTYPES to t/_helper.pm so that it can + be shared among tests. + 10. arclog: Fixed to return ref($GZIP_IO)->new instead of $GZIP_IO + in the check_gzip() method, ref($BZIP2_IO)->new instead of + $BZIP2_IO in the check_bzip2() method of the _private::IO class, + so that a same I/O handler will not be returned to different log + files. + +2007-11-24 + 1. arclog: Moved output prefix "-" check to the front in + the parse_args() subroutine. + 2. arclog: Fixed the new() method of the _private::LogFile::STDIN + class to unlink0() after checking the file type with the file + executable. + 3. t/_helper.pm: Fixed the mkrndlog_existing() subroutine to + obtain the content with anonymous array index but not @_. + 4. t/_helper.pm: Fixed the mkrndlog_*() subroutines to + return @logs and time zone variable dumps for easier debugging. + 5. t/*.t: Added a debug file to save dumped variables for easier + debugging. + 6. t/02-errors.t: Renamed to t/03-errors.t. + 7. t/*.t: Renamed the debug file "debug" to "$logfile.debug", so + that each log file can have its own variable dump. + 8. t/03-errors.t: Added "$logfile.debug" to mixing formats tests. + 9. t/_helper.pm, t/*.t: Renaming $debug to $vardump, and + "$logfile.debug" to "$logfile.vardump". + +2007-11-23 + 1. t/02-errors.t: Added tests on mixing log formats and STDOUT + output prefix. + 2. t/01-exhaust.t: Moved @LOGFMTS to t/_helper.pm so that it + can be shared among tests. + +2007-11-22 + 1. arclog: Fixed $SIG{__WARN__} to $SIG{"__WARN__"} in the + parse_args() subroutine. + 2. t/01-exhaust.t: Fixed to loop the override mode in the keep + mode. + 2. t/01-exhaust.t: Removed unused $ce and %fm. + 3. t/01-exhaust.t: Added the override mode "default". + 4. t/02-errors.t: Added. + +2007-11-20 + 1. t/01-format.t: Removed. t/03-exhaust.t should do the work. + 2. t/03-exhaust.t: Renamed to t/01-exhaust.t. + 3. t/_helper.pm: Removed the logfmts(), srctypes(), restypes(), + overtypes() subroutines, and replaced with the @LOGFMTS, + @SRCTYPES, @RESTYPES, @OVERTYPES arrays. These information are + only used once in one test. This makes it simpler. + 4. t/01-exhaust.t: Finished. Using loop to test 1800 combinations + of options, arguments, file types and file formats. + 5. t/02-apache.t: Removed. t/01-exhaust.t has replaced it. + 6. arclog: Rewrote the new() method of the _private::Format package + so that it simply returns the blessed object. Test the match + at in the check_format() method, so that it reports matching tests + at $VERBOSE > 2. + 7. t/01-exhaust.t: Removed the $nofile, $nogzip and $nobzip2 + variables. The nofile(), nogzip() and nobzip2() subroutines have + replaced them. + +2007-11-19 + 1. t/_helper.pm: Removed the mkrndlog_random() subroutine. It does + not look like I'll be using it. + 2. t/_helper.pm: Fixed the flist() subroutine to exclude non-files. + 3. t/_helper.pm: Renamed the preserve_source() subroutine to + prsrvsrc(). + 4. t/*.t: Removed the strange escaping of double-quotation character + of arclog path. + 5. t/_helper.pm: Fixed the cleanup() subroutine to skip clean-up + if the log directory does not exist. + 6. t/03-exhaust.t: Added to test all the option/argument + combinations. + +2007-11-18 + 1. arclog: Move the TYPE_PLAIN, TYPE_GZIP and TYPE_BZIP2 constants + from the _private::LogFile package to the main package, so that + other packages can use it, too. + 2. arclog: Added $one_arg in the parse_arg() subroutine to deal with + only one argument, and check if the only one argument is STDIN in + advance. If a compressd source log file is the only one argument, + remove the compresssion suffix (.gz or .bz2) from the output + prefix. + 3. _helper.pm: Added the cleanup() subroutine to clean up after + a test. + 4. _helper.pm: Added the TYPE_PLAIN, TYPE_GZIP and TYPE_BZIP2 + constants for easier use. + 5. arclog: Clean up File::Spec::Functions references. + 6. Makefile.PL and Build.PL: Changed the clean-up list from "t/log/*" + to "t/log*". + 7. t/_helper.pm: Added the preserve_source() subroutine to preserve + the source log file for reference. + +2007-11-17 + 1. arclog: Fixed the remove_temp() method of the _private::LogFile + package, so that it does not try to delete an anonymous + temporarily working file. + 2. t/01-format.t: Fixed the test so that it only remove the working + directory on success, and leave the directory on fail. + +2007-11-16 + 1. t/_helper, t/01-format.t: Added. This is the first real test + suite that test the functionality of arclog, though it does + not cover many of the arclog functionality yet. + +2007-11-15 + 1. UPGRADE, UPGRADE.zh-tw, UPGRADE.zh-cn: Added. + 2. arclog: Rename the add_record() method to add() in the + _private::Archive package. + 3. arclog: Reformatted the POD document. + 4. arclog: Added the sort() method to the _private::Archive package, + and implement the sorting ability. The new way (sort the + record index but not record themseves) seems to have lesser + memory impact than the original implementation. + 5. arclog: Added time zone to the bracked ISO 8601 format. + 6. Upgrade notes changed from 2.1.1dev3 to 2.1.1dev4. + 6. arclog: Rename the _private::Format::BracketISO package to + _private::Format::ModfISO. It is not really ISO 8601. + +2007-11-14 + 1. Changes.zh-tw, Changes.zh-cn: Removed. It is too troblesome to + maintain 3 copies of the change log. + 2. arclog: Fixed the rel2abs() subroutine and method so that it use + getpwuid() instead of getlogin(), and respect the HOME environment + variable for the current user. + 3. arclog: Renamed the new_read() method as open_read(), the + new_write() method as open_write(), the new_append() method + as open_append(). Replaced the strange architech that start + a new instance with $ioclass, with reusing the same $io object. + 4. arclog: Removed the Chinese GPL copyright message. There should + only be one version of the copyright message, and should not be + any Chinese comment. + 5. Moved from GPLv2 to GPLv3. + 6. COPYING.zh-tw, COPYING.zh-cn: Removed. The Chinese translation + of GPLv3 is not available yet. + 7. arclog: Removed subroutines arc_log(), open_src(), sort_arcs(), + save_arcs(), check_file_type(), check_gzip(), check_bzip2(), + format_number(). They are not used anymore. + 8. arclog: Fixed the read_source() method to save the record count + for later use (like progress bar). + 9. arclog: Added show_progress() to show the progress bar. + 10. Makefile.PL: Fixed to follow the Perl installation location, + but not making our own. + 11. Build.PL: Added. + 12. NEW, NEWS.zh-tw, NEWS.zh-cn: Removed, to follow the CPAN release + style. + 13. arclog: Disallow archiving a same log file more than once. + 14. arclog: Fixed parse_args() and removed the duplicated short help + on Getopt::Long::GetOptions errors. + 15. arclog: Remove the _private::Format->to_yyyymm() method. The + main utility to_yyyymm() subroutine can be used. There shouldn't + be 2 to_yyyymm() that do the same thing. + 16. arclog: Adding statistics report to the + _private::LogFile->restore_this_month() method and the + _private::Archive->store_archive() method. + 17. arclog: Removed the _private::LogFile->rel2abs() method. The + main utility rel2abs() subroutine can be used. There shouldn't + be 2 rel2abs() that do the same thing. + 18. arclog: Fixed show_progress() to reset the clean-up the start + time when progress is finished. + 19. arclog: Fixed the close() method of the _private::IO::* packages + so that KEEP_THISMONTH restart the log file, too. + 19. arclog: Added the prepend_records() method to the _private::IO::* + packages, and use prepend_records() to return the records of + this month, so that we can take the advantage of open() only once + on plain text I/O. + +2007-11-13 + 1. arclog, arclog.en.html: Changed "don't" to "do not", "can't" to + "cannot", "there's" to "there is", "it's" to "it is", "we'll" to + "we will", "I'd" to "I had", "that's" to "that is", "this month's + temporary file" to "the temporary file of this month", to help + editor syntax highlighting. + 2. arclog: Add commented single quotation mark to the end of + regular expressions that has a single quotation mark, to help + editor syntax highlighting. + 3. arclog: Changed "Deal the ~ home directories under UNIX" to + "Deal with the ~ user home directories under UNIX", + "If start from user's home directory" to + "If it starts from the user home directory". + 4. arclog: Changed "$VERBOSE >= 2" to "$VERBOSE > 1", $VERBOSE >= 1" + to "$VERBOSE > 0". + 5. arclog: Finished the _private::LogFile->check_format() method. + Fixed the parse_args() subroutine to skip empty files, and exit + if no non-empty files left. + 6. arclog: Fixed parse_args() to treat "/dev/stdin" as STDIN on + UNIX-like systems. + 7. arclog: Changed " -- " to " - " in comment. + 8. arclog: Add the new() methods of the _private::Format::* packages + so that it judges if the log record belong to its format and + return accordingly, in order to judge and initialize at a time, + to simplify the code. + 9. arclog: Add the name() methods to the _private::Format::* packages + to return the format name. + 10. arclog: Moved the check_gzip() method and the check_bzip2() method + from the _private::LogFile package to the _private::IO package, so + that other packages can access them too. Remove the $self in + the check_gzip() method and the check_bzip2() method. They are not + used at all, and these 2 methods are run as static method now. + 11. arclog: Changed $OUTPUT to $CONF{"OUTPUT"}. + 12. arclog: Added the suffix() method to the _private::IO::* packages. + 13. arclog: Added the _private::Archive package. + +2006-06-08 + 1. arclog: Revised the code with my own coding standard. + 2. Changes: ChangeLog renamed to Changes, in order to follow Perl's + convention. + +2006-06-05 + 1. arclog.pl changed to arclog. + 2. Removed Chinese text in comments. + 3. Added prototype declaration. + 4. Version number changed from x.x.x to x.xx, + as Perl preferred. + 5. Replaced GNU autoconf with ExtUtils::MakeMaker. + 6. SIGNATURE: Added. + 7. arclog: changed constants from "use vars" + to "use constant". + +2004-01-27 + 1. Reading loop changed from do {...} while() + to for(;;;) {...}, to fix the problem + "Exiting subroutine via next at ..." when + encounting and skipping a bad record. + +2003-01-04 + 1. File handler EOF read checks were fixed with + defined(). + +2002-11-13 + 1. NTP log date-time format support was added. + +2002-11-13 + 1. ISO number was added (ISO 8601) when displaying + the ISO date-time format detection. + 2. Long statistic lines are split for easy reading. + +2002-11-12 + 1. The line of $| was moved to be grouped together + with the autoflush setting. + 2. ISO date-time format support was added + (as [yyyy-mm-dd hh:nn:ss].) + 3. UNIX mailbox Received: date-time format regular + expression was added. (sendmail style. Support + not added yet.) + 4. Fixed several places where $WORKING_SRC was not + locked when created with tempfile, and not + unlocked when closed. + 5. Fixed several places where spaces are between + function name and its opening parenthesis, + according to perlstyle(1). + 6. Unnecessary parenthesis after slice and catfile + were removed. + +2002-09-26 + 1. README was rewritten for the autoconf and bzip2 + new features. + 2. INSTALL was rewritten for the autoconf. + 3. HTML documents were rewritten for the autoconf + and bzip2 new features. + 4. PGP public key file pgpkey.asc was added. + 5. Released as version 2.1.0 + +2002-09-25 + 1. GNU autoconf and automake are now used as the + configuration script, in stead of Install.PL. + Install.PL is now retired. + 2. autoconf m4 macros IM_CHECK_PERLVER and + IM_CHECK_PM were written. + 3. RELEASE_NOTES was renamed as ChangeLog. + 4. NEWS was added. + 5. AUTHORS was added. + 6. THANKS was added. + 7. TODO was added. + +2002-09-24 + 1. Compression with gzip binary is added. + 2. Compress::Zlib module is now optional but not + required. + 3. bzip2 compression is added. + 4. File::MMagic and file are now used to check the + file type, in addition to the file name suffix, + with a more preferred order. + 5. Keep this month's records is now available for + compressed source log files. + 6. check_file_type() was added to check the file + types by either File::MMa + 7. check_gzip() was added to check the gzip method + to use. + 8. check_bzip2() was added to check the bzip2 + method to use. + +2002-09-18 version 2.1.0dev2 + SourceForge Memorial Release. It's my first time + to apply a project from SourceForge. Mostly are + corrections to the documentation. SourceForge's + project page is added to the available download + source here. + 1. arclog.pl's official home page at Tavern + IMACAT's was restored. + 2. The previous version was renamed from + 2.1.0-dev1 to 2.1.0dev1, in order to unify + the version number theme. + 3. The project space at SourceForge was applied. + Package files are uploaded to SourceForge now. + 4. Project virtual host at SourceForge was set up. + 5. SourceForge was added into the documentation + as an official website and download source. + 6. Documentation were corrected. Too many places + were corrected. Ignored. + 7. HTML document was rewritten to accommodate + XHTML 1.1 recommendation. + +2002-08-31 version 2.1.0dev1 + Rewrite after almost 1 year, to be run on the + newly-released Perl 5.8.0. + 1. Filehandles are now saved and passed in global + named variables. This is the way it should be. + The old way (initialize the file handles by + duplicate the STDIN and assign them) was just + not natural. It works in Perl 5.6.1, but not in + perl 5.8.0. The duplicated filehandles are + constants, which cannot be assigned new values. + 2. Indents are changed from 1 tab to 4 columns, to + accommodate the Perl style guide documented in + perlstyle(1). This increases the code + readability. + 3. File operation error handlers are now using the + low-precedence logical "or", instead of "||", + which is recommended in perlop(1). Excessive + parentheses in file operation functions are + removed for this. + 4. Traditional Chinese files are now named with + suffix ".zh-tw" instead of ".b5". Simplified + Chinese files are now named with suffix ".zh-cn" + instead of ".gb". This is to accommodate + RFC-3066, ISO 639:1988, ISO 3166-1 for language + names. + 5. PGP signatures of distribution files are added. + 6. bzip2 distribution files are added. + +2001-07-18 version 2.0.6 + 1. A bug that regular expression cannot recognize + apache log format when a user logged in with + a username containing spaces, was solved. + 2. A bug that a hyper reference in the English + document was not specified as an absolute URL, + was fixed. + +2001-07-18 version 2.0.5 + 1. A bug that record counter $total was not + initialized at all, was fixed. + +2001-07-16 version 2.0.4 + 1. open_src() was added, as reslog.pl, to read the + source log file by complex rules. + 2. Support to reading the gzipped log file was + added. + 3. Program execution message was turned from STDOUT + to STDERR. + 4. Processing with Compress::Zlib was modified. + gzopen() was modified to open file handles if + possible. Return values was checked more + strictly. Source of error messages was + corrected. + +2001-06-29 version 2.0.3 + 1. The default keep mode was changed to + "this-month". + 2. The default keep mode "all" when "--keep" is + specified without mode, was added. + 3. The single-letter abbreviations of the override + and keep modes were added + +2001-06-29 version 2.0.2 + 1. A bug that won't delete the source empty file + under keep-delete mode, was fixed + +2001-06-28 version 2.0.1 + 1. A bug that will stop executing when an empty + file is met, was fixed. + 2. "none" keep mode was removed. "restart" and + "delete" keep modes were added. + 3. Precheck on empty files was added. It bounces + directly when an empty file is found in the + first sight. + 4. A bug that there's no documentation on --keep + option in the HTML documents, was fixed. :p + 5. The suffix of the temporary working file was + changed to ".tmp-arclog". + 6. A typo of "-dhqv" instead of "options" in the + help message was fixed + +2001-06-28 version 2.0.0 + Temporary working file was introduced to reduce the + time working on the source log file. + 1. Temporary working file was introduced. The + source log file was copied to the temporary + working file and restart first, to maximum + reduce the time occupying it, avoiding usage + of other scripts to restart the log file first. + 2. A bug that, when keep status falls back to all, + wrong variable was modified, was fixed. :p + +2001-06-28 version 1.6.1 + 1. Reuse of monthly temporary working file to + reduce the read time for multiple files. + +2001-06-27 version 1.6.0 + Multiple log files was added. + 1. Main program codes were moved to arc_log(), to + loop multiple log files. + +2001-06-11 version 1.5.1 + 1. A serious bug was fixed. :p I was planning to set + the memory limit dymatically but failed. And I + forgot to return the original codes, which + prevents the program from running. + 2. The argument checking was modified to report + error if more than necessary arguments are + supplied. + +2001-06-10 version 1.5.0 + Read from STDIN was supported. + 1. Read the log file from STDIN as "-" was added. + 2. "--prefix" option was removed. The output prefix + was specified in the second argument. + +2001-06-10 version 1.4.2dev + 1. A bug while displaying log file format + checking message, was fixed. + 2. Checking on log file format was moved to when + the first entry was read. + 3. Checking on empty log file was moved to after + the whole file was processed. + 4. rel2abs() was modified. catdir was replaced with + catfile to fixed the problem with the current + directory ".". + 5. The default behavior of --override was modified. + When STDIN is linked with a tty, the default is + ask; else, the default is fail. + +2001-06-09 version 1.4.1 + 1. English HTML document was added. + 2. HTML errors in documents were fixed. + 3. Some terms were modified in the documents. + 4. Irrelevant languages were removed in the HTML + documents. + 5. HTML document links between different languages + was added. + 6. Web page was modified so that each language has + its own pages, and was linked with each other. + +2001-06-08 version 1.4.0 + First public release. + 1. "ask" override mode was added. When the target + archived file exists, it asks the user what to + do individually. + 2. "ignore" override mode wad added. When the + target archived file exists, it ignores the + records for that month, avoid overwriting the + target file. + 3. "append" override mode was added. When the + target archived file exists, it appends the + records for that month to that file, for easy + merging on seperated log files. + 4. --sort option was added, to sort the records + in a log file by time. + 5. syslog log file format was supported. + 6. HTML documents in both Traditional and + Simplified Chinese were added. + 7. A web page was added. + +2001-06-07 version 1.3.0 + Solved the long problem that old log files will be + overwrite. + 1. Program flow was rewritten. The file open + routine when open an archived file at the first + time was seperated, to insert handlers for + existing old archived files. + 2. --override option was added, to set the + override behavior when old archived files exist. + 3. Records were now saved to temporary working + files before compressing (if they would be + compressed). The compressing is done later on + the temporary working files. + 4. --compress option was added to set if we should + compress the archived files. + 5. Checking on write previledge of the output + directory was added. + 6. A bug that rel2abs will wrongly ignore the last + part of a path when it is the current or parent + directory, was fixed. + 7. File::Basename was introduced to obtain the + short basename to report on. + 8. Anonymous subroutines was introduced to handle + simple options, like help messages or message + levels. + 9. Compressing ratio message was added. + 10. Install.PL was added in the distribution. + 11. Installation guide was added. + +2001-06-06 version 1.2.2 + 1. autoflush from IO::Handle was introduced, to + autoflush STDOUT solely under debugging mode. + 2. Temporary working file method was removed. Works + are done on the source file, to avoid the + garbages when program stopped in the middle. + 3. File::Temp was introduced to handle the + temporary working file. Records of this month + was outputs to temporary file at first. + 4. $IS_ZIP was added to control the zipping. + 5. "wb9" was introduced to zip with highest ratio. + 6. Zipping size message was added. + 7. format_number() was added to format the numbers. + 8. GNU copyright infomation was added. + 9. Chinese annotations was added. + 10. POD documents was added. + 11. Release notes was added. + 12. Readme file was added. + +2001-06-06 version 1.2.1 + 1. A serious bug that forgot to return the records + of current month, was fixed. :p + +2001-06-05 version 1.2.0 + 1. Program flow was rewritten. Now it outputs to + the target file without gzipping first. Gzip + will be done next after finishing all outouts. + 2. Message level was changed to $VERBOSE. + 3. The default message level was changed to 1. The + debugging message level was changed to 2. + 4. "quiet" option was added, with message level 0. + +2001-06-04 version 1.1.1 + 1. Some typos was fixed. + +2001-06-04 version 1.1.0 + A serious bug of the previous version, which reads + the whole log file into memory and cause system + crash, was fixed. ^^; + 1. Program flow was rewritten. Writing was done + with reading, to minimize the unnecessary memory + burden. + 2. Record sorting was removed, to reduce the memory + usage. + 3. %gz object hash was introduced to open multiple + gzipped file altogether. + 4. Getopt::Long was introduced to parse the + arguments, in replace of my own argument-parsing + routine. + 5. File::Spec::Functions was introduced to handle + the pathnames, with my own rel2abs. + 6. Cwd was introduced to obtain the current working + directory. + +2001-01-05 version 1.0.1 + Fixed some typos. + +2001-01-05 version 1.0.0 + First version, rewritten from reslog. Using + arguments-parsing and help/version message methods + from reslog. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..5673721 --- /dev/null +++ b/INSTALL @@ -0,0 +1,211 @@ +arclog Installation Guide + +* Table of Contents + + * System Requirements + * Installation Instruction + ** Install with ExtUtils::MakeMaker + ** Install with Module::Build + + +* System Requirements + + 1. Perl, version 5.8.0 or above. arclog uses 3-argument open() to +duplicate filehandles, which is only supported since 5.8.0. I have +not successfully port this onto earlier versions yet. Please tell me +if you made it. You can run perl -v to see your current Perl version. +If you do not have Perl, or if you have an older version of Perl, you +can download and install/upgrade it from Perl website. + +http://www.perl.com/ + + If you are using MS-Windows, you can download and install +ActiveState ActivePerl. + +http://www.activestate.com/ + + 2. Required Perl modules: + + * Date::Parse + + This is used to parse the timestamp of the log records. + You can download and install Date::Parse from the CPAN archive + http://search.cpan.org/dist/TimeDate/ , + or install it with the CPAN shell by running "cpan Date::Parse", + or install it with the CPANPLUS shell by running + "cpanp i Date::Parse". + Debian/Ubandu Linux users can install it by running + "apt-get install libtimedate-perl". + Red Hat/Fedora/CentOS Linux users can install it by running + "yum install perl-TimeDate". + FreeBSD users can install it by running + "ports install p5-TimeDate". + ActivePerl users can install it by running + "ppm install Date::Parse". + + If you install arclog with the CPAN or CPANPLUS shell, the above + shall be automatically installed. + + 3. Optional Perl Modules + + * File::MMagic + + This is used to check the file type. If this is not + available, arclog will look for the file executable instead. + If that is not available, too, arclog will judge the file type + by its name suffix (extension). In that case arclog will fail + when reading from STDIN. + You can download and install File::MMagic from the CPAN archive + http://search.cpan.org/dist/File-MMagic/ , + or install it with the CPAN shell by running "cpan File::MMagic", + or install it with the CPANPLUS shell by running + "cpanp i File::MMagic". + Debian/Ubandu Linux users can install it by running + "apt-get install libfile-mmagic-perl". + Red Hat/Fedora/CentOS Linux users can install it by running + "yum install perl-File-MMagic". + FreeBSD users can install it by running + "ports install p5-File-MMagic". + ActivePerl MS-Windows users can install it by running + "ppm install File::MMagic". + The alternative file.exe for MS-Windows can be obtained from + the GnuWin32 home page: http://gnuwin32.sourceforge.net/. + Be sure to save it as file.exe somewhere in your PATH. + + It is preferred to use File::MMagic. The file executable + seems to make mistakes occationally. + + * Compress::Zlib + + This is used to support read/write of gzip compressed files. + It is only needed when gzip compressed files are encountered. + If it is not available when needed, arclog will try to use the + gzip executable instead. If that is not available, too, arclog + will fail. + You can download and install Compress::Zlib from the CPAN archive + http://search.cpan.org/dist/Compress-Zlib/ , + or install it with the CPAN shell by running "cpan Compress::Zlib", + or install it with the CPANPLUS shell by running + "cpanp i Compress::Zlib". + Debian/Ubandu Linux users can install it by running + "apt-get install libcompress-zlib-perl". + Red Hat/Fedora/CentOS Linux users can install it by running + "yum install perl-Compress-Zlib". + FreeBSD users can install it by running + "ports install p5-Compress-Zlib". + ActivePerl MS-Windows users can install it by running + "ppm install Compress::Zlib". + The alternative gzip.exe for MS-Windows can be obtained from + the gzip home page: http://www.gzip.org/. + Be sure to save it as gzip.exe somewhere in your PATH. + + * Compress::Bzip2, version 2 or above + + This is used to support read/write of bzip2 compressed + files. It is only needed when bzip2 compressed files are + encountered. If it is not available when needed, arclog will + try to use the bzip2 executable instead. If that is not + available, too, arclog will fail. Notice that older versions + before 2 does not work, since file I/O compression were not + implemented yet. + You can download and install Compress::Bzip2 from the CPAN archive + http://search.cpan.org/dist/Compress-Bzip2/ , + or install it with the CPAN shell by running "cpan Compress::Bzip2", + or install it with the CPANPLUS shell by running + "cpanp i Compress::Bzip2". + Debian/Ubandu Linux users can install it by running + "apt-get install libcompress-bzip2-perl". + Red Hat/Fedora/CentOS Linux users can install it by running + "yum install perl-Compress-Bzip2". + FreeBSD users can install it by running + "ports install p5-Compress-Bzip2". + ActivePerl MS-Windows users can install it by running + "ppm install Compress::Bzip2". + The alternative bzip2.exe for MS-Windows can be obtained from + the bzip2 home page: http://www.bzip.org/. + Be sure to save it as bzip2.exe somewhere in your PATH. + + * Term::ReadKey + + This is used to display the progress bar. Without this + arclog will not display the progress bar, but nothing else is + different. The progress bar is a good visual representation of + what arclog is currently doing. + You can download and install Term::ReadKey from the CPAN archive + http://search.cpan.org/dist/TermReadKey/ , + or install it with the CPAN shell by running "cpan Term::ReadKey", + or install it with the CPANPLUS shell by running + "cpanp i Term::ReadKey". + Debian/Ubandu Linux users can install it by running + "apt-get install libterm-readkey-perl". + Red Hat/Fedora/CentOS Linux users can install it by running + "yum install perl-TermReadKey". + FreeBSD users can install it by running + "ports install p5-Term-ReadKey". + ActivePerl MS-Windows users can install it by running + "ppm install Term::ReadKey". + + +* Installation Instruction + + If you are upgrading from arclog.pl 2.1.1dev4 or earlier, please +read UPGRADE for some upgrade instruction. + +** Install with ExtUtils::MakeMaker + + arclog uses standard Perl installation with ExtUtils::MakeMaker. +Follow these steps: + + % perl Makefile.PL + % make + % make test + % make install + + When running make install, make sure you have the priviledge to +write to the installation location. This usually requires the root +priviledge. + + If you are using ActivePerl under MS-Windows, you should use +nmake instead of make. nmake can be obtained from the Microsoft FTP +site. + +ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe + + If you want to install into another location, you can set the +PREFIX. For example, to install into your home when you are not +root: + + % perl Makefile.PL PREFIX=/home/jessica + + Refer to the docuemntation of ExtUtils::MakeMaker for more +installation options (by running perldoc ExtUtils::MakeMaker). + + +** Install with Module::Build + + You can install with Module::Build instead, if you prefer. +Follow these steps: + + % perl Build.PL + % ./Build + % ./Build test + % ./Build install + + When running ./Build install, make sure you have the priviledge to +write to the installation location. This usually requires the root +priviledge. + + If you want to install into another location, you can set the +--prefix. For example, to install into your home when you are not +root: + + % perl Build.PL --prefix=/home/jessica + + Refer to the docuemntation of Module::Build for more +installation options (by running perldoc Module::Build). + + +imacat +2008-11-17 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/INSTALL.zh-cn b/INSTALL.zh-cn new file mode 100644 index 0000000..28ddeda --- /dev/null +++ b/INSTALL.zh-cn @@ -0,0 +1,186 @@ +arclog °²×°Ö¸ÄÏ + +¡òĿ¼ + + ¡òϵͳÐèÇó + ¡ò°²×°Ö¸ÄÏ + ¡ò¡òÒÔ ExtUtils::MakeMaker °²×° + ¡ò¡òÒÔ Module::Build °²×° + + +¡òϵͳÐèÇó + + 1. Perl 5.8.0 »òÒÔÉÏ¡£ arclog ʹÓÃÈý²ÎÊýµÄ open() ÒÔ¸´ÖƵµ°¸²Ù×÷£¬ +ÎÒ»¹²»ÖªµÀÔõô¸Äдµ½¸üÔçµÄ°æ±¾ÉÏÖ´ÐС£ÈôÄã¿ÉÒÔ¸Äдµ½¸üÔçµÄ°æ±¾ÉÏÖ´ÐУ¬ +Çë¸æËßÎÒ¡£Äã¿ÉÒÔÊäÈë perl -v ²éѯÄãÄ¿Ç°µÄ Perl °æ±¾¡£Ä¿Ç°´ó¶àÊýµÄ Unix +ϵͳ¶¼ÓÐ Perl ¡£Èç¹ûÄãûÓÐ Perl »òÐèÒªÉý¼¶£¬¿ÉÒÔµ½ Perl ÍøÕ¾ÏÂÔØ°²×°×î +аæ Perl ¡£ + + http://www.perl.com/ + + ÈôÄãÓà MS-Windows £¬¿ÉÒÔÏÂÔØ°²×° ActiveState ¹«Ë¾µÄ ActivePerl ¡£ + + http://www.activestate.com/ + + 2. Ðè´îÅäµÄ Perl Ä£×飺ÎÞ¡£ + + * Date::Parse + + ÕâÊDZæʶ¼Ç¼ʱ¼äÓõġ£ + Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Date::Parse £º + http://search.cpan.org/dist/TimeDate/ £¬ + »òÓà CPAN Shell Ö´ÐÐ cpan Date::Parse °²×°£¬ + »òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Date::Parse °²×°¡£ + ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + apt-get install libtimedate-perl °²×°¡£ + ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + yum install perl-TimeDate °²×°¡£ + ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ports install p5-TimeDate °²×°¡£ + ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ppm install Date::Parse °²×°¡£ + + ÈôÄãÓÉ CPAN »ò CPANPLUS Shell °²×° arclog £¬»á×Ô¶¯°ïÄã°²×°ÒÔÉÏËù + ÐèµÄÄ£×é¡£ + + 3. Ñ¡ÅäµÄ Perl Ä£×飺 + + * File::MMagic + + ÕâÊǼì²éµµ°¸ÀàÐÍÓõġ£ÈôûÓа²×°£¬ arclog »áÊÔÖøÈ¥ÕÒ file ³Ì + ʽ´úÌæ¡£Èô»¹ÕÒ²»µ½£¬ arclog »á¸ÄÓõµÎ²£¨¸±µµÃû£©Åжϵµ°¸ÀàÐÍ¡£Õâ + ʱÈô´Ó±ê×¼ÊäÈë¶Áµµ£¬ arclog »áÎÞ·¨Åжϡ£ + Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° File::MMagic £º + http://search.cpan.org/dist/File-MMagic/ £¬ + »òÓà CPAN Shell Ö´ÐÐ cpan File::MMagic °²×°£¬ + »òÓà CPANPLUS Shell Ö´ÐÐ cpanp i File::MMagic °²×°¡£ + ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + apt-get install libfile-mmagic-perl °²×°¡£ + ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + yum install perl-File-MMagic °²×°¡£ + ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ports install p5-File-MMagic °²×°¡£ + ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ppm install File::MMagic °²×°¡£ + ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà file.exe ³Ìʽ£¬¿ÉÒÔÓÉ + GnuWin32 ÍøÕ¾ÏÂÔØ£º http://gnuwin32.sourceforge.net/ ¡£ + ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ file.exe ¡£ + + ½¨ÒéÓà File::MMagic ¡£ file ³Ìʽż¶û»áÎóÅС£ + + * Compress::Zlib + + ÕâÊÇ´¦Àí gzip ѹËõµµÓõģ¬Ö»Óд¦Àí gzip ѹËõµµÊ±²Å»áÓõ½¡£Èô + ÒªÓÃʱûÓа²×°£¬ arclog »áÊÔÖø¸ÄÓà gzip ³Ìʽ´úÌæ¡£Èô»¹ÕÒ²»µ½£¬ + arclog ¾ÍÎÞ·¨Ö´ÐС£ + Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Compress::Zlib £º + http://search.cpan.org/dist/Compress-Zlib/ £¬ + »òÓà CPAN Shell Ö´ÐÐ cpan Compress::Zlib °²×°£¬ + »òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Compress::Zlib °²×°¡£ + ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + apt-get install libcompress-zlib-perl °²×°¡£ + ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + yum install perl-Compress-Zlib °²×°¡£ + ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ports install p5-Compress-Zlib °²×°¡£ + ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ppm install Compress::Zlib °²×°¡£ + ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà gzip.exe ³Ìʽ£¬¿ÉÒÔÓÉ + gzip ÍøÕ¾ÏÂÔØ£º http://www.gzip.org/ ¡£ + ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ gzip.exe ¡£ + + * Compress::Bzip2 µÚ¶þ°æÒÔÉÏ + + ÕâÊÇÖ§Ô®¶Áд bzip2 ѹËõµµÓõģ¬Ö»Óд¦Àí bzip2 ѹËõµµÊ±²Å»áÓà + µ½¡£ÈôÒªÓÃʱûÓа²×°£¬ arclog »áÊÔÖø¸ÄÓà bzip2 ³Ìʽ´úÌæ¡£Èô»¹ÕÒ + ²»µ½£¬ arclog ¾ÍÎÞ·¨Ö´ÐС£ + Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Compress::Bzip2 £º + http://search.cpan.org/dist/Compress-Bzip2/ £¬ + »òÓà CPAN Shell Ö´ÐÐ cpan Compress::Bzip2 °²×°£¬ + »òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Compress::Bzip2 °²×°¡£ + ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + apt-get install libcompress-bzip2-perl °²×°¡£ + ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + yum install perl-Compress-Bzip2 °²×°¡£ + ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ports install p5-Compress-Bzip2 °²×°¡£ + ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ppm install Compress::Bzip2 °²×°¡£ + ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà bzip2.exe ³Ìʽ£¬¿ÉÒÔÓÉ + bzip2 ÍøÕ¾ÏÂÔØ£º http://www.bzip.org/ ¡£ + ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ bzip2.exe ¡£ + + * Term::ReadKey + + ÕâÊÇÏÔʾ½ø¶ÈÁÐÓõģ¬ÈôûÓа²×°£¬¾Í²»»áÏÔʾ½ø¶ÈÁС£´ËÍâ²»»áÓÐ + ÈκÎÎÊÌâ¡£½ø¶ÈÁпÉÒÔÈÃÄã¶Ô arclog µÄ¹¤×÷½ø¶ÈһĿÁËÈ»¡£ + Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Term::ReadKey £º + http://search.cpan.org/dist/TermReadKey/ £¬ + »òÓà CPAN Shell Ö´ÐÐ cpan Term::ReadKey °²×°£¬ + »òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Term::ReadKey °²×°¡£ + ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + apt-get install libterm-readkey-perl °²×°¡£ + ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + yum install perl-TermReadKey °²×°¡£ + ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ports install p5-Term-ReadKey °²×°¡£ + ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ + ppm install Term::ReadKey °²×°¡£ + + +¡ò°²×°Ö¸ÄÏ + + ÈôÄãÊÇÓÉ arclog.pl 2.1.1dev4 ÒÔÇ°µÄ°æ±¾Éý¼¶£¬Çë²ÎÔÄ UPGRADE.zh-tw +µµµÄÉý¼¶ËµÃ÷¡£ + +¡ò¡òÒÔ ExtUtils::MakeMaker °²×° + + arclog Óà Perl ±ê×¼µÄ ExtUtils::MakeMaker °²×°£¬³ÌÐòÈçÏ£º + + % perl Makefile.PL + % make + % make test + % make install + + ÔÚ make install Ç°£¬ÇëÏÈÈ·ÈÏÄãÓÐÔÚ°²×°Ä¿Â¼´æµµµÄȨÏÞ¡£Í¨³£Õâʱºò +ÒªÇл»Îª root £¬²ÅÄÜ°²×°´æµµ¡£ + + ÈôÄãÊÇÓà MS-Windows Ï嵀 ActivePerl £¬ make Çë¸ÄÓà nmake ¡£ nmake +¿ÉÓÉ΢ÈíµÄ FTP Õ¾ÏÂÔØ£º + + ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe + + ÈôÒª°²×°µ½ÆäËüµØ·½£¬ÇëÉ趨ºÃ PREFIX ¡£ÀýÈ磬һ°ãʹÓÃÕߣ¬Òª°²×°ÔÚ +×Ô¼ºµÄĿ¼ÏÂʱ£º + + % perl Makefile.PL PREFIX=/home/jessica + + ÒªÖªµÀ¸ü¶à°²×°Ñ¡ÏîµÄϸ½Ú£¬Çë²ÎÔÄ ExtUtils::MakeMaker µÄ˵Ã÷£¨ÇëÖ´ +ÐÐ perldoc ExtUtils::MakeMaker £©¡£ + + +¡ò¡òÒÔ Module::Build °²×° + + ÈôÄãϲ»¶£¬Ò²¿ÉÒÔÓà Module::Build °²×°£¬³ÌÐòÈçÏ£º + + % perl Build.PL + % ./Build + % ./Build test + % ./Build install + + ÔÚ ./Build install Ç°£¬ÇëÏÈÈ·ÈÏÄãÓÐÔÚ°²×°Ä¿Â¼´æµµµÄȨÏÞ¡£Í¨³£Õâʱ +ºòÒªÇл»Îª root £¬²ÅÄÜ°²×°´æµµ¡£ + + ÈôÒª°²×°µ½ÆäËüµØ·½£¬ÇëÉ趨ºÃ --prefix ¡£ÀýÈ磬һ°ãʹÓÃÕߣ¬Òª°²×° +ÔÚ×Ô¼ºµÄĿ¼ÏÂʱ£º + + % perl Build.PL --prefix=/home/jessica + + ÒªÖªµÀ¸ü¶à°²×°Ñ¡ÏîµÄϸ½Ú£¬Çë²ÎÔÄ Module::Build µÄ˵Ã÷£¨ÇëÖ´ÐÐ +perldoc Module::Build £©¡£ + + +ÒÀÂêè +2008-11-18 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/INSTALL.zh-tw b/INSTALL.zh-tw new file mode 100644 index 0000000..cf66eea --- /dev/null +++ b/INSTALL.zh-tw @@ -0,0 +1,186 @@ +arclog ¦w¸Ë«ü«n + +¡·¥Ø¿ý + + ¡·¨t²Î»Ý¨D + ¡·¦w¸Ë«ü«n + ¡·¡·¥H ExtUtils::MakeMaker ¦w¸Ë + ¡·¡·¥H Module::Build ¦w¸Ë + + +¡·¨t²Î»Ý¨D + + 1. Perl 5.8.0 ©Î¥H¤W¡C arclog ¨Ï¥Î¤T°Ñ¼Æªº open() ¥H½Æ»sÀÉ®×¾Þ§@¡A +§ÚÁÙ¤£ª¾¹D«ç»ò§ï¼g¨ì§ó¦­ªºª©¥»¤W°õ¦æ¡C­Y©p¥i¥H§ï¼g¨ì§ó¦­ªºª©¥»¤W°õ¦æ¡A +½Ð§i¶D§Ú¡C©p¥i¥H¿é¤J perl -v ¬d¸ß©p¥Ø«eªº Perl ª©¥»¡C¥Ø«e¤j¦h¼Æªº Unix +¨t²Î³£¦³ Perl ¡C¦pªG©p¨S¦³ Perl ©Î»Ý­nª@¯Å¡A¥i¥H¨ì Perl ºô¯¸¤U¸ü¦w¸Ë³Ì +·sª© Perl ¡C + + http://www.perl.com/ + + ­Y©p¥Î MS-Windows ¡A¥i¥H¤U¸ü¦w¸Ë ActiveState ¤½¥qªº ActivePerl ¡C + + http://www.activestate.com/ + + 2. »Ý·f°tªº Perl ¼Ò²Õ¡GµL¡C + + * Date::Parse + + ³o¬O¿ëÃÑ°O¿ý®É¶¡¥Îªº¡C + ©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Date::Parse ¡G + http://search.cpan.org/dist/TimeDate/ ¡A + ©Î¥Î CPAN Shell °õ¦æ cpan Date::Parse ¦w¸Ë¡A + ©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Date::Parse ¦w¸Ë¡C + ­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + apt-get install libtimedate-perl ¦w¸Ë¡C + ­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + yum install perl-TimeDate ¦w¸Ë¡C + ­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ports install p5-TimeDate ¦w¸Ë¡C + ­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ppm install Date::Parse ¦w¸Ë¡C + + ­Y©p¥Ñ CPAN ©Î CPANPLUS Shell ¦w¸Ë arclog ¡A·|¦Û°ÊÀ°©p¦w¸Ë¥H¤W©Ò + »Ýªº¼Ò²Õ¡C + + 3. ¿ï°tªº Perl ¼Ò²Õ¡G + + * File::MMagic + + ³o¬OÀˬdÀÉ®×Ãþ«¬¥Îªº¡C­Y¨S¦³¦w¸Ë¡A arclog ·|¸ÕµÛ¥h§ä file µ{ + ¦¡¥N´À¡C­YÁ٧䤣¨ì¡A arclog ·|§ï¥ÎÀɧÀ¡]°ÆÀɦW¡^§PÂ_ÀÉ®×Ãþ«¬¡C³o + ®É­Y±q¼Ð·Ç¿é¤JŪÀÉ¡A arclog ·|µLªk§PÂ_¡C + ©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë File::MMagic ¡G + http://search.cpan.org/dist/File-MMagic/ ¡A + ©Î¥Î CPAN Shell °õ¦æ cpan File::MMagic ¦w¸Ë¡A + ©Î¥Î CPANPLUS Shell °õ¦æ cpanp i File::MMagic ¦w¸Ë¡C + ­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + apt-get install libfile-mmagic-perl ¦w¸Ë¡C + ­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + yum install perl-File-MMagic ¦w¸Ë¡C + ­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ports install p5-File-MMagic ¦w¸Ë¡C + ­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ppm install File::MMagic ¦w¸Ë¡C + ­Y©p­n¦b MS-Windows ¤U¨Ï¥Î file.exe µ{¦¡¡A¥i¥H¥Ñ + GnuWin32 ºô¯¸¤U¸ü¡G http://gnuwin32.sourceforge.net/ ¡C + ½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° file.exe ¡C + + «Øij¥Î File::MMagic ¡C file µ{¦¡°¸º¸·|»~§P¡C + + * Compress::Zlib + + ³o¬O³B²z gzip À£ÁYÀɥΪº¡A¥u¦³³B²z gzip À£ÁYÀɮɤ~·|¥Î¨ì¡C­Y + ­n¥Î®É¨S¦³¦w¸Ë¡A arclog ·|¸ÕµÛ§ï¥Î gzip µ{¦¡¥N´À¡C­YÁ٧䤣¨ì¡A + arclog ´NµLªk°õ¦æ¡C + ©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Compress::Zlib ¡G + http://search.cpan.org/dist/Compress-Zlib/ ¡A + ©Î¥Î CPAN Shell °õ¦æ cpan Compress::Zlib ¦w¸Ë¡A + ©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Compress::Zlib ¦w¸Ë¡C + ­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + apt-get install libcompress-zlib-perl ¦w¸Ë¡C + ­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + yum install perl-Compress-Zlib ¦w¸Ë¡C + ­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ports install p5-Compress-Zlib ¦w¸Ë¡C + ­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ppm install Compress::Zlib ¦w¸Ë¡C + ­Y©p­n¦b MS-Windows ¤U¨Ï¥Î gzip.exe µ{¦¡¡A¥i¥H¥Ñ + gzip ºô¯¸¤U¸ü¡G http://www.gzip.org/ ¡C + ½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° gzip.exe ¡C + + * Compress::Bzip2 ²Ä¤Gª©¥H¤W + + ³o¬O¤ä´©Åª¼g bzip2 À£ÁYÀɥΪº¡A¥u¦³³B²z bzip2 À£ÁYÀɮɤ~·|¥Î + ¨ì¡C­Y­n¥Î®É¨S¦³¦w¸Ë¡A arclog ·|¸ÕµÛ§ï¥Î bzip2 µ{¦¡¥N´À¡C­YÁÙ§ä + ¤£¨ì¡A arclog ´NµLªk°õ¦æ¡C + ©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Compress::Bzip2 ¡G + http://search.cpan.org/dist/Compress-Bzip2/ ¡A + ©Î¥Î CPAN Shell °õ¦æ cpan Compress::Bzip2 ¦w¸Ë¡A + ©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Compress::Bzip2 ¦w¸Ë¡C + ­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + apt-get install libcompress-bzip2-perl ¦w¸Ë¡C + ­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + yum install perl-Compress-Bzip2 ¦w¸Ë¡C + ­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ports install p5-Compress-Bzip2 ¦w¸Ë¡C + ­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ppm install Compress::Bzip2 ¦w¸Ë¡C + ­Y©p­n¦b MS-Windows ¤U¨Ï¥Î bzip2.exe µ{¦¡¡A¥i¥H¥Ñ + bzip2 ºô¯¸¤U¸ü¡G http://www.bzip.org/ ¡C + ½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° bzip2.exe ¡C + + * Term::ReadKey + + ³o¬OÅã¥Ü¶i«×¦C¥Îªº¡A­Y¨S¦³¦w¸Ë¡A´N¤£·|Åã¥Ü¶i«×¦C¡C¦¹¥~¤£·|¦³ + ¥ô¦ó°ÝÃD¡C¶i«×¦C¥i¥HÅý©p¹ï arclog ªº¤u§@¶i«×¤@¥ØÁAµM¡C + ©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Term::ReadKey ¡G + http://search.cpan.org/dist/TermReadKey/ ¡A + ©Î¥Î CPAN Shell °õ¦æ cpan Term::ReadKey ¦w¸Ë¡A + ©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Term::ReadKey ¦w¸Ë¡C + ­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + apt-get install libterm-readkey-perl ¦w¸Ë¡C + ­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + yum install perl-TermReadKey ¦w¸Ë¡C + ­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ports install p5-Term-ReadKey ¦w¸Ë¡C + ­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ + ppm install Term::ReadKey ¦w¸Ë¡C + + +¡·¦w¸Ë«ü«n + + ­Y©p¬O¥Ñ arclog.pl 2.1.1dev4 ¥H«eªºª©¥»ª@¯Å¡A½Ð°Ñ¾\ UPGRADE.zh-tw +Àɪºª@¯Å»¡©ú¡C + +¡·¡·¥H ExtUtils::MakeMaker ¦w¸Ë + + arclog ¥Î Perl ¼Ð·Çªº ExtUtils::MakeMaker ¦w¸Ë¡Aµ{§Ç¦p¤U¡G + + % perl Makefile.PL + % make + % make test + % make install + + ¦b make install «e¡A½Ð¥ý½T»{©p¦³¦b¦w¸Ë¥Ø¿ý¦sÀɪºÅv­­¡C³q±`³o®É­Ô +­n¤Á´«¬° root ¡A¤~¯à¦w¸Ë¦sÀÉ¡C + + ­Y©p¬O¥Î MS-Windows ¤Uªº ActivePerl ¡A make ½Ð§ï¥Î nmake ¡C nmake +¥i¥Ñ·L³nªº FTP ¯¸¤U¸ü¡G + + ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe + + ­Y­n¦w¸Ë¨ì¨ä¥¦¦a¤è¡A½Ð³]©w¦n PREFIX ¡C¨Ò¦p¡A¤@¯ë¨Ï¥ÎªÌ¡A­n¦w¸Ë¦b +¦Û¤vªº¥Ø¿ý¤U®É¡G + + % perl Makefile.PL PREFIX=/home/jessica + + ­nª¾¹D§ó¦h¦w¸Ë¿ï¶µªº²Ó¸`¡A½Ð°Ñ¾\ ExtUtils::MakeMaker ªº»¡©ú¡]½Ð°õ +¦æ perldoc ExtUtils::MakeMaker ¡^¡C + + +¡·¡·¥H Module::Build ¦w¸Ë + + ­Y©p³ßÅw¡A¤]¥i¥H¥Î Module::Build ¦w¸Ë¡Aµ{§Ç¦p¤U¡G + + % perl Build.PL + % ./Build + % ./Build test + % ./Build install + + ¦b ./Build install «e¡A½Ð¥ý½T»{©p¦³¦b¦w¸Ë¥Ø¿ý¦sÀɪºÅv­­¡C³q±`³o®É +­Ô­n¤Á´«¬° root ¡A¤~¯à¦w¸Ë¦sÀÉ¡C + + ­Y­n¦w¸Ë¨ì¨ä¥¦¦a¤è¡A½Ð³]©w¦n --prefix ¡C¨Ò¦p¡A¤@¯ë¨Ï¥ÎªÌ¡A­n¦w¸Ë +¦b¦Û¤vªº¥Ø¿ý¤U®É¡G + + % perl Build.PL --prefix=/home/jessica + + ­nª¾¹D§ó¦h¦w¸Ë¿ï¶µªº²Ó¸`¡A½Ð°Ñ¾\ Module::Build ªº»¡©ú¡]½Ð°õ¦æ +perldoc Module::Build ¡^¡C + + +¨Ìº¿¿ß +2008-11-18 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..6c6f675 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,39 @@ +arclog +arclog.en.html +arclog.zh-cn.html +arclog.zh-tw.html +AUTHORS +AUTHORS.zh-cn +AUTHORS.zh-tw +Build.PL +Changes +COPYING +fdl.txt +INSTALL +INSTALL.zh-cn +INSTALL.zh-tw +Makefile.PL +MANIFEST This list of files +META.yml +NEWS +pgpkey.asc +README +README.zh-cn +README.zh-tw +SIGNATURE +t/00-signature.t +t/01-exhaust.t +t/02-several.t +t/03-fallback.t +t/04-errors.t +t/99-pod.t +t/_helper.pm +THANKS +THANKS.zh-cn +THANKS.zh-tw +TODO +TODO.zh-cn +TODO.zh-tw +UPGRADE +UPGRADE.zh-cn +UPGRADE.zh-tw diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..671b5e1 --- /dev/null +++ b/META.yml @@ -0,0 +1,14 @@ +--- #YAML:1.0 +name: arclog +version: 3.04 +abstract: Archive log files monthly +license: gpl +author: + - imacat +generated_by: ExtUtils::MakeMaker version 6.38 +distribution_type: module +requires: + Date::Parse: 0 +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.3.html + version: 1.3 diff --git a/Makefile.PL b/Makefile.PL new file mode 100755 index 0000000..75d7d3e --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,91 @@ +#! /usr/bin/perl -w +# Makefile.PL: Installation configuration for ExtUtils::MakeMaker +use 5.008; +use strict; +use warnings; +use Config qw(%Config); +use ExtUtils::MakeMaker; + +# Check if there is any old file +use vars qw(%old_version); +%old_version = qw(); +foreach (qw(/usr/sbin/arclog.pl + /usr/sbin/arclog + /usr/share/man/man8/arclog.pl.8 + /usr/share/man/man8/arclog.8 + /usr/local/sbin/arclog.pl + /usr/local/sbin/arclog + /usr/local/share/man/man8/arclog.pl.8 + /usr/local/share/man/man8/arclog.8)) { + $old_version{$_} = 1 if -e $_; +} +foreach my $cnf (qw(installman1dir installsiteman1dir installvendorman1dir + man1dir man1direxp siteman1dir siteman1direxp sysman + vendorman1dir vendorman1direxp)) { + next unless defined $Config{$cnf} && -d $Config{$cnf}; + $_ = $Config{$cnf}; + s/\/man1$/\/man8/; + $old_version{"$_/arclog.8"} = 1 if -e "$_/arclog.8"; + $old_version{"$_/arclog.pl.8"} = 1 if -e "$_/arclog.pl.8"; +} +foreach my $cnf (qw(installscript installsitescript installvendorscript + scriptdir scriptdirexp sitescript sitescriptexp + vendorscript vendorscriptexp + bin binexp installbin installsitebin installvendorbin + sitebin sitebinexp vendorbin vendorbinexp)) { + next unless defined $Config{$cnf} && -d $Config{$cnf}; + $_ = $Config{$cnf}; + s/\/bin$/\/sbin/; + $old_version{"$_/arclog"} = 1 if -e "$_/arclog"; + $old_version{"$_/arclog.pl"} = 1 if -e "$_/arclog.pl"; +} +if (keys %old_version > 0) { + $_ = join " ", sort keys %old_version; + warn << "EOT"; +-- Old Files Found +You may remove the following old files after "make install": + $_ +EOT +} + +# Optional prerequisite modules +use vars qw(%OPT_PREREQ); +%OPT_PREREQ = ( + "File::MMagic" => 0, + "Compress::Zlib" => 0, + "Compress::Bzip2" => 2, + "Term::ReadKey" => 0, +); +delete $OPT_PREREQ{$_} + foreach grep eval "use $_ $OPT_PREREQ{$_} qw(); 1;", sort keys %OPT_PREREQ; +if (keys %OPT_PREREQ > 0) { + $_ = join " ", sort keys %OPT_PREREQ; + warn << "EOT"; +-- Optional Prerequisites +You may wish to install these modules altogether. + $_ +EOT +} + +WriteMakefile( + NAME => "arclog", + VERSION_FROM => "arclog", + ABSTRACT => "Archive log files monthly", + AUTHOR => "imacat ", + LICENSE => "gpl", + PREREQ_PM => { + "Date::Parse" => 0, + }, + SIGN => 1, + + EXE_FILES => [ "arclog" ], + dist => { + COMPRESS => "gzip -9", + SUFFIX => ".gz", + }, + clean => { + FILES => "t/logs*", + }, +); + +__END__ diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..60556ba --- /dev/null +++ b/NEWS @@ -0,0 +1,29 @@ +New in 3.04: +* Documentation fixes. + +New in 3.03: +* Test suite fixes. +* Required Perl version number compatible to older versions, to work + with the Perl 5.10 warning. + +New in 3.02: +* Test suite improvement. + +New in 3.01: +* Test suite improvement. + +New in 3.00: +* Name changed from arclog.pl to arclog. +* Perl's s build system ExtUtils::MakeMaker and Module::Build are + used instead of GNU autoconf. +* Added test suite that help quality assurance. +* License updated to GPLv3. + +New in 2.1.0: +* Added support for bzip2 compression. +* Added support for gzip compression with gzip binary instead of + Compress::Zlib. +* Added the GNU autoconf configuration script. + +New in 2.1.0dev2: +* Documentation fixes. diff --git a/README b/README new file mode 100644 index 0000000..36b87a0 --- /dev/null +++ b/README @@ -0,0 +1,67 @@ +arclog - Archive the log files monthly + + Copyright (c) 2001-2007 imacat. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + arclog archives the log files monthly. It strips off previous months' +log records from the log file, and save them to compressed archive files +named logfile.yyyymm. It then saves the hard disk space and prevents +potential attacks on log files. + + Currently, arclog supports Apache access log, Syslog, NTP, Apache 1 SSL +engine log and my own bracketed, modified ISO date/time log file formats, and +gzip and bzip2 compression methods. Several software projects log (or can +log) in a format compatible with the Apache access log, like CUPS, ProFTPD, +Pure-FTPd... etc., and arclog can archive their Apache-like log files, too. + + +* Documentation + + Type "perldoc arclog" to read the arclog manual. + + +* Installation + + Read INSTALL for instructions on how to install arclog. + + +* News, Changes and Updates + + Refer to the Changes for changes, bug fixes, updates, new functions, etc. + + +* Support + + arclog's website is at http://arclog.sourceforge.net/. Visit the website +for the current information of arclog. + + arclog has a mailing list arclog-users@lists.sourceforge.net. If you have +any question, comment, bug report, patch, please send it to the mailing list. +Join the list at https://lists.sourceforge.net/lists/listinfo/arclog-users . +Do not send mails directly to me unless you have private business with me. +The mailing list has an archive. People having the same trouble as you may +search the archive, find the answer and save a lot of time. + + +* License + + This program is distributed under GNU Gneral Pulbic License (GPL). Please +refer to the COPYING file for the copyright and the license of this program. + + +imacat ^_*' +2007-12-03 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/README.zh-cn b/README.zh-cn new file mode 100644 index 0000000..d58008d --- /dev/null +++ b/README.zh-cn @@ -0,0 +1,58 @@ +arclog - ¼Ç¼µµÃ¿Ô¹鵵³Ìʽ + + °æȨËùÓÐ (c) 2001-2007 ÒÀÂêè + + ±¾³ÌʽÊÇ×ÔÓÉÈíÌ壬Äú¿ÉÒÔ×ñÕÕ×ÔÓÉÈíÌå»ù½ð»á (Free Software Foundation) + ³ö°æµÄ GNU ͨÓù«¹²Ðí¿ÉÖ¤Ìõ¿î (GNU General Public License) µÚÈý°æÀ´ÐÞ + ¸ÄºÍÖØз¢²¼ÕâÒ»³Ìʽ£¬»òÕß×ÔÓÉÑ¡ÔñʹÓÃÈκθüеİ汾¡£ + + ·¢²¼ÕâÒ»³ÌʽµÄÄ¿µÄÊÇÏ£ÍûËüÓÐÓ㬵«Ã»ÓÐÈκε£±£¡£ÉõÖÁûÓÐÊʺÏÌض¨Ä¿µÄ + ¶øÒþº¬µÄµ£±£¡£¸üÏêϸµÄÇé¿öÇë²ÎÔÄ GNU ͨÓù«¹²Ðí¿ÉÖ¤¡£ + + ÄúÓ¦¸ÃÒѾ­ºÍ³ÌʽһÆðÊÕµ½Ò»·Ý GNU ͨÓù«¹²Ðí¿ÉÖ¤µÄ¸±±¾¡£Èç¹û»¹Ã»ÓУ¬²Î + ÔÄ¡£ + + arclog ÊÇÿÔ¹鵵³Ìʽ£¬½«¼Ç¼µµÖУ¬Ç°ÔµļǼ°´Ô·ÝѹËõ¹éµµ£¬ÒÔ½ÚÊ¡Ó²µú¿Õ +¼ä£¬²¢±ÜÃâ¼Ç¼µµ±»ÓÐÐÄÈËÊ¿ÆÆ»µ¡£ + +¡¡¡¡arclog Ä¿Ç°Ö§Ô® Apache ¡¢ Syslog ¡¢ NTP ¡¢ Apache 1 SSL engine log ¼°ÎÒ×Ô +¼ºÓõÄÀ¨»¡ ISO ÐÞÕý¸ñʽÎåÖÖ¸ñʽµÄ¼Ç¼µµ£¬Óë gzip ºÍ bzip2 Á½ÖÖѹËõ·¨¡£ºÜ¶à³Ì +ʽ¶¼¿ÉÒÔÓà Apache ÏàÈݼǼµµ¸ñʽ¼Ç¼£¬Èç CUPS ¡¢ ProFTPD ¡¢ Pure-FTPd¡­µÈ£¬ +arclog Ò²¿ÉÒԹ鵵ÕâЩ Apache ÏàÈݸñʽµÄ¼Ç¼µµ¡£ + +¡ò˵Ã÷Îļþ + +¡¡¡¡ÇëÊäÈë perldoc arclog £¬ÔĶÁ arclog µÄ˵Ã÷¡£ + + +¡ò°²×°Ö¸ÄÏ + +¡¡¡¡ÇëÏêÔÄ INSTALL.zh-tw µµ°¸µÄ°²×°Ö¸ÄÏ¡£ + + +¡ò¸üС¢ÐÞÕý˵Ã÷ + +¡¡¡¡ÇëÏêÔÄ Changes µµ°¸µÄ¸üÐÂ˵Ã÷£¬ÒÔÁ˽âÐÂÔö¹¦ÄÜ¡¢ÎÊÌâÐÞÕý¡¢¸üеȡ£ + + +¡ò¼¼ÊõÖ§Ô® + +¡¡¡¡arclog µÄÍøÕ¾ÔÚ http://arclog.sourceforge.net/ £¬ÇëËæʱÉÏÍøÁ˽â×îÐÂѶϢ¡£ + +¡¡¡¡arclog ÓÐÒ»¸öÓʼþͨѶ arclog-users@lists.sourceforge.net £¬ÈôÓÐÈκÎÎÊÌâ¡¢ +½¨Òé¡¢ÎÊÌâ»Ø±¨¡¢ÐÞ²¹³Ìʽ£¬Çë¼Äµ½ÓʼþͨѶÉÏ¡£ÇëÁ¬ÉÏ +https://lists.sourceforge.net/lists/listinfo/arclog-users ¼ÓÈëÎÒÃǵÄÓʼþͨѶ +¡£³ý·ÇÊÇ˽ÈËÊÂÎñ£¬·ñÔòÇë²»ÒªÖ±½ÓдПøÎÒ¡£ÓʼþͨѶ»á×Ô¶¯¹éµµ£¬ÈÕºóÈôÆäËûÈËÓÐ +ÏàͬÎÊÌ⣬¿ÉÒÔÖ±½ÓÔÚͨѶ¾ÉµµÖÐÕÒµ½´ð°¸£¬½ÚÊ¡´ó¼Ò±¦¹óµÄʱ¼ä¡£ + + +¡ò°æȨÉùÃ÷ + +¡¡¡¡±¾³ÌʽÒÀ GNU ͨÓù«¹²Ðí¿ÉÖ¤ (GPL) °æȨ·¢²¼£¬Çë²Î¿¼ COPYING µµ°¸µÄ˵Ã÷£¬ +Á˽Ȿ³ÌʽµÄ°æȨÊÚȨÄÚÈÝ¡£ + + +ÒÀÂêè imacat ^_*' +2007-12-03 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/README.zh-tw b/README.zh-tw new file mode 100644 index 0000000..e2c523a --- /dev/null +++ b/README.zh-tw @@ -0,0 +1,58 @@ +arclog - °O¿ýÀɨC¤ëÂkÀɵ{¦¡ + + ª©Åv©Ò¦³ (c) 2001-2007 ¨Ìº¿¿ß + + ¥»µ{¦¡¬O¦Û¥Ñ³nÅé¡A±z¥i¥H¿í·Ó¦Û¥Ñ³nÅé°òª÷·| (Free Software Foundation) + ¥Xª©ªº GNU ³q¥Î¤½¦@³\¥iÃÒ±ø´Ú (GNU General Public License) ²Ä¤Tª©¨Ó­× + §ï©M­«·sµo§G³o¤@µ{¦¡¡A©ÎªÌ¦Û¥Ñ¿ï¾Ü¨Ï¥Î¥ô¦ó§ó·sªºª©¥»¡C + + µo§G³o¤@µ{¦¡ªº¥Øªº¬O§Æ±æ¥¦¦³¥Î¡A¦ý¨S¦³¥ô¦ó¾á«O¡C¬Æ¦Ü¨S¦³¾A¦X¯S©w¥Øªº + ¦ÓÁô§tªº¾á«O¡C§ó¸Ô²Óªº±¡ªp½Ð°Ñ¾\ GNU ³q¥Î¤½¦@³\¥iÃÒ¡C + + ±zÀ³¸Ó¤w¸g©Mµ{¦¡¤@°_¦¬¨ì¤@¥÷ GNU ³q¥Î¤½¦@³\¥iÃÒªº°Æ¥»¡C¦pªGÁÙ¨S¦³¡A°Ñ + ¾\¡C + + arclog ¬O¨C¤ëÂkÀɵ{¦¡¡A±N°O¿ýÀɤ¤¡A«e¤ëªº°O¿ý«ö¤ë¥÷À£ÁYÂkÀÉ¡A¥H¸`¬ÙµwºÐªÅ +¶¡¡A¨ÃÁקK°O¿ýÀɳQ¦³¤ß¤H¤h¯}Ãa¡C + +¡@¡@arclog ¥Ø«e¤ä´© Apache ¡B Syslog ¡B NTP ¡B Apache 1 SSL engine log ¤Î§Ú¦Û +¤v¥Îªº¬A©· ISO ­×¥¿®æ¦¡¤­ºØ®æ¦¡ªº°O¿ýÀÉ¡A»P gzip ©M bzip2 ¨âºØÀ£ÁYªk¡C«Ü¦hµ{ +¦¡³£¥i¥H¥Î Apache ¬Û®e°O¿ýÀɮ榡°O¿ý¡A¦p CUPS ¡B ProFTPD ¡B Pure-FTPd¡Kµ¥¡A +arclog ¤]¥i¥HÂkÀɳo¨Ç Apache ¬Û®e®æ¦¡ªº°O¿ýÀÉ¡C + +¡·»¡©ú¤å¥ó + +¡@¡@½Ð¿é¤J perldoc arclog ¡A¾\Ū arclog ªº»¡©ú¡C + + +¡·¦w¸Ë«ü«n + +¡@¡@½Ð¸Ô¾\ INSTALL.zh-tw Àɮתº¦w¸Ë«ü«n¡C + + +¡·§ó·s¡B­×¥¿»¡©ú + +¡@¡@½Ð¸Ô¾\ Changes Àɮתº§ó·s»¡©ú¡A¥HÁA¸Ñ·s¼W¥\¯à¡B°ÝÃD­×¥¿¡B§ó·sµ¥¡C + + +¡·§Þ³N¤ä´© + +¡@¡@arclog ªººô¯¸¦b http://arclog.sourceforge.net/ ¡A½ÐÀH®É¤WºôÁA¸Ñ³Ì·s°T®§¡C + +¡@¡@arclog ¦³¤@­Ó¶l¥ó³q°T arclog-users@lists.sourceforge.net ¡A­Y¦³¥ô¦ó°ÝÃD¡B +«Øij¡B°ÝÃD¦^³ø¡B­×¸Éµ{¦¡¡A½Ð±H¨ì¶l¥ó³q°T¤W¡C½Ð³s¤W +https://lists.sourceforge.net/lists/listinfo/arclog-users ¥[¤J§Ú­Ìªº¶l¥ó³q°T +¡C°£«D¬O¨p¤H¨Æ°È¡A§_«h½Ð¤£­nª½±µ¼g«Hµ¹§Ú¡C¶l¥ó³q°T·|¦Û°ÊÂkÀÉ¡A¤é«á­Y¨ä¥L¤H¦³ +¬Û¦P°ÝÃD¡A¥i¥Hª½±µ¦b³q°TÂÂÀɤ¤§ä¨ìµª®×¡A¸`¬Ù¤j®aÄ_¶Qªº®É¶¡¡C + + +¡·ª©ÅvÁn©ú + +¡@¡@¥»µ{¦¡¨Ì GNU ³q¥Î¤½¦@³\¥iÃÒ (GPL) ª©Åvµo§G¡A½Ð°Ñ¦Ò COPYING Àɮתº»¡©ú¡A +ÁA¸Ñ¥»µ{¦¡ªºª©Åv±ÂÅv¤º®e¡C + + +¨Ìº¿¿ß imacat ^_*' +2007-12-03 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/SIGNATURE b/SIGNATURE new file mode 100644 index 0000000..98ed260 --- /dev/null +++ b/SIGNATURE @@ -0,0 +1,61 @@ +This file contains message digests of all files listed in MANIFEST, +signed via the Module::Signature module, version 0.55. + +To verify the content in this distribution, first make sure you have +Module::Signature installed, then type: + + % cpansign -v + +It will check each file's integrity, as well as the signature's +validity. If "==> Signature verified OK! <==" is not displayed, +the distribution may already have been compromised, and you should +not run its Makefile.PL or Build.PL. + +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +SHA1 91ced1a733e7448edc19eab22482508d58d7b284 AUTHORS +SHA1 c4c98cc9e7ac5e119752587d0322280a7a71d205 AUTHORS.zh-cn +SHA1 eb60ee204fcf7244fc0774ac34d05a35a281e82b AUTHORS.zh-tw +SHA1 412193f4d2ed686ed0041b3c8835461e9d440d68 Build.PL +SHA1 8624bcdae55baeef00cd11d5dfcfa60f68710a02 COPYING +SHA1 36d19de5f62f40b91d486cad7698586b56e11968 Changes +SHA1 22d80da796c88630915181541744461cf96e7f1a INSTALL +SHA1 00a2c93770fcb552b327cbc4438dc990d6d9c43d INSTALL.zh-cn +SHA1 b042e58841bcadd56bfb6dbdd52452bcd4215626 INSTALL.zh-tw +SHA1 e71173ba2be13190d51294a2b132940766c65bfd MANIFEST +SHA1 92bc0b6b053289e807fe9b339a5817cb8d7369b1 META.yml +SHA1 60c8024233f1b70534758aea970fe1a7d82bfff8 Makefile.PL +SHA1 f18322a97f991168d6a85104a8ce658f959431a1 NEWS +SHA1 183e9814e38c0fdaebc1624be8f1a32fb6649562 README +SHA1 38db34e5c056d10691f755e524b34e66bca0a981 README.zh-cn +SHA1 a01809cac1f61ced88f47d823b45c381706fe582 README.zh-tw +SHA1 3b55f1f8407b87ab8627e3a12c50836ad6429f5c THANKS +SHA1 aeb1c5d44e73163c50f0997203e49a8a029064d6 THANKS.zh-cn +SHA1 19bff4abc6eca9c61c875e8aef50fd3d44ec8034 THANKS.zh-tw +SHA1 48f5fff8ffb487089aa9fdcb9279ba3fd1c508c0 TODO +SHA1 00e67ef5268c66e8648c5f14da8e7912e2c2f9c5 TODO.zh-cn +SHA1 2e45a15082ae9630230235d7538dec63c6df18c8 TODO.zh-tw +SHA1 1f0c3a74a765a905339dd24ac344cc0ad48933e5 UPGRADE +SHA1 ef05ca4632730a76dbaf9119b3da95b7477aa6c3 UPGRADE.zh-cn +SHA1 182c625b0f13c8dcc4641adff1499bd705d9a53a UPGRADE.zh-tw +SHA1 0e45847a9428d8ec1154803e55641d1045f89f4b arclog +SHA1 dd80c79b178517f082ae9503889c36d0cb4e6cc8 arclog.en.html +SHA1 9604c39bf6d69cf3fd8bcb036f547761edf04961 arclog.zh-cn.html +SHA1 ab9d8bd14a36d68790c71044de1d7a67a34b41c5 arclog.zh-tw.html +SHA1 bd75d59f9d7d9731bfabdc48ecd19e704d218e38 fdl.txt +SHA1 520fdcf4374af210380db9e0fdaea44c904a15fc pgpkey.asc +SHA1 525f414c7a0aadc61240a4b0959ca2cda7514c75 t/00-signature.t +SHA1 96374acc016c20bdbe31dc4ce8eac89f59b642e6 t/01-exhaust.t +SHA1 504ee1023c7db80427dc633e1611521984909e9d t/02-several.t +SHA1 497de13a15b6721c5cf5c0be9551dc25a841312c t/03-fallback.t +SHA1 212ae878ffdf68742339b452ab631b0cbb340880 t/04-errors.t +SHA1 b85626024d610808bd0909989dcfb9fb20a40485 t/99-pod.t +SHA1 e698db4a84dbe5200cf37ad73667a595a23d9d04 t/_helper.pm +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.7 (GNU/Linux) + +iD8DBQFHVgHci9gubzC5S1wRAgU7AJwK/IesoIYHuMd2vOeyEqYrf25ViwCcD0cc +tgiH/AXhrVXGRy97R25j7H4= +=Jrgq +-----END PGP SIGNATURE----- diff --git a/THANKS b/THANKS new file mode 100644 index 0000000..833a7f2 --- /dev/null +++ b/THANKS @@ -0,0 +1,2 @@ + Thanks to SourceForge's people to kindly provide hosting of the +arclog project. diff --git a/THANKS.zh-cn b/THANKS.zh-cn new file mode 100644 index 0000000..f9b89d3 --- /dev/null +++ b/THANKS.zh-cn @@ -0,0 +1 @@ +¡¡¡¡¸Ðл SourceForge Ìṩ¼ÜÉè arclog ¡£ diff --git a/THANKS.zh-tw b/THANKS.zh-tw new file mode 100644 index 0000000..ee0083d --- /dev/null +++ b/THANKS.zh-tw @@ -0,0 +1 @@ +¡@¡@·PÁ SourceForge ´£¨Ñ¬[³] arclog ¡C diff --git a/TODO b/TODO new file mode 100644 index 0000000..a132d2b --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ + 1. Multi-lingual support, with Traditional and Simplified Chinese + messages. diff --git a/TODO.zh-cn b/TODO.zh-cn new file mode 100644 index 0000000..a7592fa --- /dev/null +++ b/TODO.zh-cn @@ -0,0 +1 @@ + 1. ¶àÓﻯ£¬¼ÓÉÏÕý¼òÖÐÎÄѶϢ¡£ diff --git a/TODO.zh-tw b/TODO.zh-tw new file mode 100644 index 0000000..fcf3af6 --- /dev/null +++ b/TODO.zh-tw @@ -0,0 +1 @@ + 1. ¦h»y¤Æ¡A¥[¤W¥¿Â²¤¤¤å°T®§¡C diff --git a/UPGRADE b/UPGRADE new file mode 100644 index 0000000..e554874 --- /dev/null +++ b/UPGRADE @@ -0,0 +1,47 @@ +Upgrade Instruction + + Here are a few hints for people upgrading from 2.1.1dev4 or earlier: + +* The Script Name is Changed from arclog.pl to arclog + + This is obvious. If you have any scripts or cron jobs that are running +arclog, remember to modify your script for the new name. Of course, you can +rename arclog to arclog.pl. It will still work. + + The reason I changed the script and project name is that: A dot "." in +the project name is not valid everywhere. At least SourceForge don't accept +it. Besides, "arclog" is enough for a script name under UNIX. The ".pl" file +name suffix/extension may be convienent for MS-Windows, but MS-Windows users +won't run it with explorer file name association anyway, and there is a pl2bat +to convert "arclog" to "arclog.bat", which would make more sense. The only +disadvantage is that I use UltraEdit, which depends on the file name extension +for the automatic syntax highlighting rules. But this is not much trouble. I +can manuall set it anyway. + + +* The Default Installation Location Is at /usr/bin + + Also, the man page is at /usr/share/man/man1/arclog.1. This is to follow +Perl's standard convension, and to avoid breaking ExtUtils::MakeMaker with +future versions. + + When you run "perl Makefile.PL" or "perl Build.PL", it will hint a list of +old files found to be removed. Please delete them manually. + + If you saved them in other places, you have to delete them yourself. + + Also, if you have any scripts or cron jobs that are running arclog, remember +to modify your script for the new arclog location. Of course, you can copy +arclog to the original location. It will still work. + + +* The Argument of --keep and --override Options Are Required Now + + Support for omitting --keep or --override argument is removed. This helps +avoiding confusion for the log file name and the option arguments. + + +imacat +2007-11-26 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/UPGRADE.zh-cn b/UPGRADE.zh-cn new file mode 100644 index 0000000..35acd20 --- /dev/null +++ b/UPGRADE.zh-cn @@ -0,0 +1,39 @@ +Éý¼¶Ö¸ÄÏ + +¡¡¡¡ÈôÄãÓÉ 2.1.1dev4 »ò֮ǰµÄ°æ±¾Éý¼¶£¬ÇëÔĶÁÒÔÏÂ˵Ã÷£º + +¡òµµÃûÓÉ arclog.pl ¸ÄΪ arclog + +¡¡¡¡ÕâºÜÃ÷ÏÔ°É¡£ :p ÈôÄãÓÐд³Ìʽ£¬»òÉ趨 cron ÅųÌÀ´Ö´ÐÐ arclog £¬Çë¼ÇµÃ¸ü¸Äµµ +Ãû¡£²»¹ýÄãÒ²¿ÉÒÔ°Ñ arclog ¸ÄÃû»ØÔ­À´µÄ arclog.pl £¬²»»áÓÐÈκÎÎÊÌâ¡£ + +¡¡¡¡¸ÄÃûÔ­ÒòÈçÏ£º×¨°¸Ãû³Æº¬¡¸.¡¹»á´¦´¦Åö±Ú¡£ SourceForget ¾Í²»½ÓÊܺ¬¡¸.¡¹µÄר +°¸Ãû³Æ¡£´ËÍ⣬³ÌʽÃû³Æ arclog ÔÚ UNIX ϾͿÉÒÔÅÜÁË¡£¸±µµÃû .pl ËäÈ»ÔÚ +MS-Windows Ï·½±ã£¬µ«·´Õý MS-Windows ÏÂÒ²²»»áÖ±½ÓµãÁ½ÏÂÒÀ¸±µµÃûÖ´ÐС£¶øÇÒ»¹ÓÐ +pl2bat ¿ÉÒÔ°Ñ arclog ת³É arclog.bat £¬ÕâÑù·´¶ø±È½ÏºÏÀí¡£Î¨Ò»²»±ãµÄÊÇÎÒÓõıà +¼­Æ÷ UltraEdit ÒÀ¸±µµÃû¾ö¶¨³ÌʽÓïÑÔÓï·¨±êʾ£¬²»¹ýÕâҲûʲô´ó²»ÁË£¬ÊÖ¶¯Éè³Ìʽ +ÓïÑԾͺÃÁË¡£ + + +¡òÔ¤É谲װĿ¼Ϊ /usr/bin + +¡¡¡¡ËµÃ÷µµÔòÔÚ /usr/share/man/man1/arclog.1 ¡£ÕâÊÇΪ·ûºÏ Perl µÄ±ê×¼°²×°Á÷³Ì£¬ +±ÖÃâÆÆ»µ ExtUtils::MakeMaker µÄÔ¤ÉèÉ趨£¬Ôì³ÉÈÕºóÉý¼¶µÄÎÊÌâ¡£ + +¡¡¡¡Ö´ÐÐ perl Makefile.PL »ò perl Build.PL ʱ£¬»áÌáʾÄãËùÔÚϵͳÉÏ·¢Ïֵĵľɵµ +°¸¡£Çë×ÔÐÐɾ³ý¡£ÈôÄã³Ìʽ´æÔÚÆäËüµØ·½£¬Çë¼ÇµÃÒª×Ô¼ºÉ¾µô¡£ + +¡¡¡¡ÈôÄãÓÐд³Ìʽ£¬»òÉ趨 cron ÅųÌÀ´Ö´ÐÐ arclog £¬Çë¼ÇµÃ¸ü¸ÄµµÃû¡£²»¹ýÄãÒ²¿ÉÒÔ +°Ñ arclog ´æµ½Ô­À´µÄĿ¼ȥ£¬²»»áÓÐÈκÎÎÊÌâ¡£ + + +¡ò --keep ºÍ --override Ñ¡ÏîÏÖÔÚÒ»¶¨Òª¼Óģʽ²ÎÊý + +¡¡¡¡ÒÔÇ°¿ÉÒÔÖ±½ÓÓà --keep ºÍ --override Ñ¡Ï²»¼Ó²ÎÊý£¬ÏÖÔÚÒ»¶¨Òª¼Ó²ÎÊý£¬Òﱆ +Ãâ»ìÏýÑ¡ÏîµÄ²ÎÊýºÍÒª´¦ÀíµÄ¼Ç¼µµÃû¡£ + + +ÒÀÂêè +2007-11-26 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/UPGRADE.zh-tw b/UPGRADE.zh-tw new file mode 100644 index 0000000..e2bc295 --- /dev/null +++ b/UPGRADE.zh-tw @@ -0,0 +1,39 @@ +ª@¯Å«ü«n + +¡@¡@­Y©p¥Ñ 2.1.1dev4 ©Î¤§«eªºª©¥»ª@¯Å¡A½Ð¾\Ū¥H¤U»¡©ú¡G + +¡·ÀɦW¥Ñ arclog.pl §ï¬° arclog + +¡@¡@³o«Ü©úÅã§a¡C :p ­Y©p¦³¼gµ{¦¡¡A©Î³]©w cron ±Æµ{¨Ó°õ¦æ arclog ¡A½Ð°O±o§ó§ïÀÉ +¦W¡C¤£¹L©p¤]¥i¥H§â arclog §ï¦W¦^­ì¨Óªº arclog.pl ¡A¤£·|¦³¥ô¦ó°ÝÃD¡C + +¡@¡@§ï¦W­ì¦]¦p¤U¡G±M®×¦WºÙ§t¡u.¡v·|³B³B¸I¾À¡C SourceForget ´N¤£±µ¨ü§t¡u.¡vªº±M +®×¦WºÙ¡C¦¹¥~¡Aµ{¦¡¦WºÙ arclog ¦b UNIX ¤U´N¥i¥H¶]¤F¡C°ÆÀɦW .pl ÁöµM¦b +MS-Windows ¤U¤è«K¡A¦ý¤Ï¥¿ MS-Windows ¤U¤]¤£·|ª½±µÂI¨â¤U¨Ì°ÆÀɦW°õ¦æ¡C¦Ó¥BÁÙ¦³ +pl2bat ¥i¥H§â arclog Âন arclog.bat ¡A³o¼Ë¤Ï¦Ó¤ñ¸û¦X²z¡C°ß¤@¤£«Kªº¬O§Ú¥Îªº½s +¿è¾¹ UltraEdit ¨Ì°ÆÀɦW¨M©wµ{¦¡»y¨¥»yªk¼Ð¥Ü¡A¤£¹L³o¤]¨S¤°»ò¤j¤£¤F¡A¤â°Ê³]µ{¦¡ +»y¨¥´N¦n¤F¡C + + +¡·¹w³]¦w¸Ë¥Ø¿ý¬° /usr/bin + +¡@¡@»¡©úÀÉ«h¦b /usr/share/man/man1/arclog.1 ¡C³o¬O¬°²Å¦X Perl ªº¼Ð·Ç¦w¸Ë¬yµ{¡A +±Í§K¯}Ãa ExtUtils::MakeMaker ªº¹w³]³]©w¡A³y¦¨¤é«áª@¯Åªº°ÝÃD¡C + +¡@¡@°õ¦æ perl Makefile.PL ©Î perl Build.PL ®É¡A·|´£¥Ü©p©Ò¦b¨t²Î¤Wµo²{ªºªºÂÂÀÉ +®×¡C½Ð¦Û¦æ§R°£¡C­Y©pµ{¦¡¦s¦b¨ä¥¦¦a¤è¡A½Ð°O±o­n¦Û¤v§R±¼¡C + +¡@¡@­Y©p¦³¼gµ{¦¡¡A©Î³]©w cron ±Æµ{¨Ó°õ¦æ arclog ¡A½Ð°O±o§ó§ïÀɦW¡C¤£¹L©p¤]¥i¥H +§â arclog ¦s¨ì­ì¨Óªº¥Ø¿ý¥h¡A¤£·|¦³¥ô¦ó°ÝÃD¡C + + +¡· --keep ©M --override ¿ï¶µ²{¦b¤@©w­n¥[¼Ò¦¡°Ñ¼Æ + +¡@¡@¥H«e¥i¥Hª½±µ¥Î --keep ©M --override ¿ï¶µ¡A¤£¥[°Ñ¼Æ¡A²{¦b¤@©w­n¥[°Ñ¼Æ¡A¥HÁ× +§K²V²c¿ï¶µªº°Ñ¼Æ©M­n³B²zªº°O¿ýÀɦW¡C + + +¨Ìº¿¿ß +2007-11-26 +imacat@mail.imacat.idv.tw +http://www.imacat.idv.tw/ diff --git a/arclog b/arclog new file mode 100755 index 0000000..e817114 --- /dev/null +++ b/arclog @@ -0,0 +1,2884 @@ +#! /usr/bin/perl -w +# arclog: Archive the log files monthly + +# Copyright (c) 2001-2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# First written: 2001-01-05 + +package main; +use 5.008; +use strict; +use warnings; +use ExtUtils::MakeMaker qw(); +use Fcntl qw(:flock); +use File::Basename qw(basename); +use IO::Handle qw(autoflush); +use Getopt::Long qw(GetOptions); +use Cwd qw(cwd); +use File::Basename qw(basename fileparse); +use File::Spec::Functions qw(devnull file_name_is_absolute path catfile + splitdir curdir updir); +use File::Temp qw(tempfile); +use Config qw(); +use base qw(Exporter); +use vars qw(@EXPORT @EXPORT_OK); +BEGIN { +@EXPORT = qw(); +push @EXPORT, qw(COMPRESS_GZIP COMPRESS_BZIP2 COMPRESS_NONE); +push @EXPORT, qw(OVERRIDE_OVERWRITE OVERRIDE_APPEND OVERRIDE_IGNORE OVERRIDE_FAIL OVERRIDE_ASK); +push @EXPORT, qw(KEEP_ALL KEEP_RESTART KEEP_DELETE KEEP_THISMONTH); +push @EXPORT, qw(TYPE_PLAIN TYPE_GZIP TYPE_BZIP2); +push @EXPORT, qw(TMP_SUFFIX whereis to_yyyymm format_number rel2abs); +@EXPORT_OK = @EXPORT; +# Prototype declaration +sub main(); +sub parse_args(); +sub whereis($); +sub to_yyyymm($); +sub format_number($); +sub rel2abs($;$); +} + +our ($THIS_FILE, $VERBOSE); +use vars qw($VERSION); +$THIS_FILE = basename($0); +$VERSION = "3.04"; +$VERBOSE = 1; + +our (%CONF, @LOGFILES, $THIS_MONTH, $PROGBAR); +use vars qw(%WHEREIS); +$THIS_MONTH = to_yyyymm $^T; + +# Constants +# The compress mode +use constant COMPRESS_GZIP => "gzip"; +use constant COMPRESS_BZIP2 => "bzip2"; +use constant COMPRESS_NONE => "none"; +use constant DEFAULT_COMPRESS => COMPRESS_GZIP; +# The override mode +use constant OVERRIDE_OVERWRITE => "overwrite"; +use constant OVERRIDE_APPEND => "append"; +use constant OVERRIDE_IGNORE => "ignore"; +use constant OVERRIDE_FAIL => "fail"; +use constant OVERRIDE_ASK => "ask"; +sub DEFAULT_OVERRIDE() { -t STDIN? OVERRIDE_ASK: OVERRIDE_FAIL; } +# The keep mode +use constant KEEP_ALL => "all"; +use constant KEEP_RESTART => "restart"; +use constant KEEP_DELETE => "delete"; +use constant KEEP_THISMONTH => "this-month"; +use constant DEFAULT_KEEP => KEEP_THISMONTH; +# The file types +use constant TYPE_PLAIN => "text/plain"; +use constant TYPE_GZIP => "application/x-gzip"; +use constant TYPE_BZIP2 => "application/x-bzip2"; +# Other constants +use constant TMP_SUFFIX => ".tmp-arclog"; +use constant GZIP_SUFFIX => ".gz"; +use constant BZIP2_SUFFIX => ".bz2"; +use constant DEFAULT_PROGBAR => 1; +use constant DEFAULT_SORT => 0; + +use vars qw($VERMSG $HELPMSG); +our $SHORTHELP; +$VERMSG = "$THIS_FILE v$VERSION by imacat "; +$SHORTHELP = "Try `$THIS_FILE --help' for more information."; +$HELPMSG = << "EOT"; +Usage: $THIS_FILE [options] logfile... [output] +Archive the log files monthly. + + logfile The log file to be archived. + output The prefix of the output files. The output files will be + named as pre.yyyymm, ie: pre.200001, pre.200002. If not + specified, the default prefix is the logfile pathname. + --compress method Compress the archived files. Available methods are: + gzip, bzip2 and none. The default is gzip. + --sort Sort the records in the log files by time. + --nosort Do not sort the records. (default) + --override mode The override behavior when the target archived files + exist. Available modes are: overwrite, append, ignore, + fail and ask. If not specified, the default is "ask" on + TTY, "fail" for else. + --keep mode What to keep in the logfile. Available modes are: all, + restart, delete and this-month. If not specified, the + default is "this-month". + -d,--debug Display debug messages. Multiple --debug to debug more. + -q,--quiet Disable debug messages. An opposite that cancels the + effect of --debug. + -h,--help Display this help. + -v,--version Display version number. + +EOT + +main; +exit 0; + +# main: Main program +sub main() { + local ($_, %_); + my %ARC; + + # Parse the arguments + parse_args; + + # Create the temporary working files + $_->create_temp foreach @LOGFILES; + # Read the source files to temporary working files + $_->read_source foreach @LOGFILES; + # Process each log file + %ARC = qw(); + foreach my $logfile (@LOGFILES) { + my ($label, $count, $dropped); + print STDERR "Archiving " . $logfile->{"file"} . " ... " + if $VERBOSE > 0 && !$CONF{"PROGBAR"}; + print STDERR "\n" if $VERBOSE > 1 && !$CONF{"PROGBAR"}; + $label = $logfile->{"file"}; + $label = "-" . substr($label, -13) if length $label > 14; + ($count, $dropped) = (0, 0); + if ($CONF{"PROGBAR"}) { + $PROGBAR = _private::ProgressBar->new($label, $logfile->{"count"}); + $PROGBAR->update(0); + } + # Sort each log record by month + while (defined($_ = $logfile->read_record)) { + my ($month, $FH); + $month = $logfile->{"format"}->parse_month($_); + # Skip malformed records whose time is not parsable + if (!defined $month) { + $dropped++; + + # This month to keep + } elsif ($CONF{"KEEP"} eq KEEP_THISMONTH && $month eq $THIS_MONTH) { + $logfile->save_this_month($_); + + # Months to archive + } else { + # A new month + $ARC{$month} = _private::Archive->new($month) + if !exists $ARC{$month}; + $ARC{$month}->add($_) if !$ARC{$month}->{"ignore"}; + } + $count++; + $PROGBAR->update($count) if $CONF{"PROGBAR"}; + } + undef $PROGBAR if $CONF{"PROGBAR"}; + print STDERR "$count records\n" + if $VERBOSE > 0 && !$CONF{"PROGBAR"}; + warn "Dropping $dropped malformed records\n" + if $dropped > 0; + } + # Sorting + if ($CONF{"SORT"}) { + foreach my $month (sort grep !$ARC{$_}->{"ignore"}, keys %ARC) { + $ARC{$month}->sort; + } + } + # Store the archived log records + foreach my $month (sort grep !$ARC{$_}->{"ignore"}, keys %ARC) { + $ARC{$month}->store_archive; + } + # Return the records of this month + if ($CONF{"KEEP"} eq KEEP_THISMONTH) { + $_->restore_this_month foreach @LOGFILES; + } + # Remove the temporarily working files + $_->remove_temp foreach @LOGFILES; + + # Print the statistics + printf STDERR "%d archive files written, %d seconds elapsed.\n", + scalar(grep !$ARC{$_}->{"ignore"}, keys %ARC), (time - $^T) + if $VERBOSE > 0; + return; +} + +# parse_args: Parse the arguments +sub parse_args() { + local ($_, %_); + my ($has_stdin, $one_arg); + + %CONF = qw(); + $CONF{"SORT"} = DEFAULT_SORT; + # Get the arguments + eval { + local $SIG{"__WARN__"} = sub { die $_[0]; }; + Getopt::Long::Configure(qw(no_auto_abbrev bundling)); + GetOptions( "compress|c=s"=>sub { + if ($_[1] =~ /^(?:g|gzip)$/i) { + $CONF{"COMPRESS"} = COMPRESS_GZIP; + } elsif ($_[1] =~ /^(?:b|bzip2)$/i) { + $CONF{"COMPRESS"} = COMPRESS_BZIP2; + } elsif ($_[1] =~ /^(?:n|none)$/i) { + $CONF{"COMPRESS"} = COMPRESS_NONE; + } else { + die "$THIS_FILE: Unknown compress mode: $_[1]\n"; + } }, + "nocompress"=>sub { $CONF{"COMPRESS"} = COMPRESS_NONE; }, + "sort|s!"=>\$CONF{"SORT"}, + "override|o=s"=>sub { + if ($_[1] =~ /^(?:o|overwrite)$/i) { + $CONF{"OVERRIDE"} = OVERRIDE_OVERWRITE; + } elsif ($_[1] =~ /^(?:a|append)$/i) { + $CONF{"OVERRIDE"} = OVERRIDE_APPEND; + } elsif ($_[1] =~ /^(?:i|ignore)$/i) { + $CONF{"OVERRIDE"} = OVERRIDE_IGNORE; + } elsif ($_[1] =~ /^(?:f|fail)$/i) { + $CONF{"OVERRIDE"} = OVERRIDE_FAIL; + } elsif ($_[1] =~ /^(?:ask)$/i) { + $CONF{"OVERRIDE"} = OVERRIDE_ASK; + } else { + die "$THIS_FILE: Unknown override mode: $_[1]\n"; + } }, + "keep|k=s"=>sub { + if ($_[1] =~ /^(?:a|all)$/i) { + $CONF{"KEEP"} = KEEP_ALL; + } elsif ($_[1] =~ /^(?:r|restart)$/i) { + $CONF{"KEEP"} = KEEP_RESTART; + } elsif ($_[1] =~ /^(?:d|delete)$/i) { + $CONF{"KEEP"} = KEEP_DELETE; + } elsif ($_[1] =~ /^(?:t|this-month)$/i) { + $CONF{"KEEP"} = KEEP_THISMONTH; + } else { + die "$THIS_FILE: Unknown keep mode: $_[1]\n"; + } }, + "debug|d+"=>\$VERBOSE, + "quiet|q"=>sub { $VERBOSE-- if $VERBOSE > 0; }, + "help|h"=>sub { print $HELPMSG; exit 0; }, + "version|v"=>sub { print "$VERMSG\n"; exit 0; }); + }; + die "$THIS_FILE: $@$SHORTHELP\n" if $@ ne ""; + + # Save the original STDIN and STDOUT + open $STDIN, "<&", \*STDIN or die "$THIS_FILE: STDIN: $!"; + open $STDOUT, ">&", \*STDOUT or die "$THIS_FILE: STDOUT: $!"; + + # Set the verbose level + autoflush STDERR if $VERBOSE > 1; + $CONF{"PROGBAR"} = DEFAULT_PROGBAR; + $CONF{"PROGBAR"} = 0 if $VERBOSE == 0 || !-t STDERR; + if ($CONF{"PROGBAR"}) { + # Check if we have Term::ReadKey + $CONF{"PROGBAR"} = 0 unless eval { require Term::ReadKey; 1; }; + } + + # Check the arguments + # Arguments are source files + @LOGFILES = qw(); + while (@ARGV > 0) { + $_ = shift @ARGV; + # Treat /dev/stdin as - on UNIX-like systems + $_ = "-" if $_ eq "/dev/stdin" && devnull eq "/dev/null"; + push @LOGFILES, $_; + $_{$_} = 1; + } + die "$THIS_FILE: Which log file do you want to archive?\n$SHORTHELP\n" + if @LOGFILES == 0; + $has_stdin = scalar grep $_ eq "-", @LOGFILES; + # The output prefix + $one_arg = (@LOGFILES == 1); + if ($one_arg) { + # STDIN must specify the output prefix + die "$THIS_FILE: You must specify the output prefix for STDIN\n$SHORTHELP\n" + if $LOGFILES[0] eq "-"; + $CONF{"OUTPUT"} = $LOGFILES[0]; + } else { + $CONF{"OUTPUT"} = pop @LOGFILES; + die "$THIS_FILE: You cannot specify STDOUT as the output prefix\n$SHORTHELP\n" + if $CONF{"OUTPUT"} eq "-"; + } + # Check the duplicates - after removing the output prefix + %_ = qw(); + foreach (@LOGFILES) { + die "$THIS_FILE: $_: You can only specify a file once\n$SHORTHELP\n" + if exists $_{$_}; + $_{$_} = 1; + } + + # Set the default override mode + $CONF{"OVERRIDE"} = DEFAULT_OVERRIDE if !exists $CONF{"OVERRIDE"}; + # Set the default keep mode + $CONF{"KEEP"} = DEFAULT_KEEP if !exists $CONF{"KEEP"}; + # Set the default compress mode + $CONF{"COMPRESS"} = DEFAULT_COMPRESS if !exists $CONF{"COMPRESS"}; + + # Cannot keep the records of this month back in STDIN + if ($has_stdin && $CONF{"KEEP"} eq KEEP_THISMONTH) { + warn "$THIS_FILE: Cannot keep this-month in STDIN. Change to keep all.\n"; + $CONF{"KEEP"} = KEEP_ALL; + } + # Cannot delete STDIN + if ($has_stdin && $CONF{"KEEP"} eq KEEP_DELETE) { + warn "$THIS_FILE: Cannot delete the STDIN. Change to keep all.\n"; + $CONF{"KEEP"} = KEEP_ALL; + } + # Cannot restart STDIN + if ($has_stdin && $CONF{"KEEP"} eq KEEP_RESTART) { + warn "$THIS_FILE: Cannot restart the STDIN. Change to keep all.\n"; + $CONF{"KEEP"} = KEEP_ALL; + } + # Cannot get the log file and the answer both from STDIN + if ($has_stdin && $CONF{"OVERRIDE"} eq OVERRIDE_ASK) { + warn "$THIS_FILE: Cannot read from STDIN in ask mode. Change to fail mode.\n"; + $CONF{"OVERRIDE"} = "fail"; + } + + # Check the log files + @LOGFILES = map new _private::LogFile($_), @LOGFILES; + if ((@_ = grep $_->{"is_empty"}, @LOGFILES) > 0) { + print STDERR "Skipping empty files: " . join(", ", map $_->{"file"}, @_) . "\n" + if $VERBOSE > 0; + @LOGFILES = grep !$_->{"is_empty"}, @LOGFILES; + # Close empty files - do this after $_->{"is_empty"}, + # so that $_->{"is_empty"} is still accessible. + foreach (@_) { + $_->{"io"}->close; + undef $_; + } + if (@LOGFILES == 0) { + print STDERR "$THIS_FILE: No non-empty files left. Exiting.\n" + if $VERBOSE > 0; + exit 0; + } + $has_stdin = scalar grep $_->{"stdin"}, @LOGFILES; + } + # Check if the formats of the files are consistent + %_ = map { $_->{"format"} => 1 } @LOGFILES; + die "$THIS_FILE: Cannot archive log files in different formats at a time.\n" + . join "", map sprintf(" %s : %s\n", $_->{"file"}, $_->{"format"}), + @LOGFILES + if keys %_ > 1; + $CONF{"FORMAT"} = $LOGFILES[0]->{"format"}; + + # Check the output file prefix + # Strip the filename suffix of the compressed files + if ($one_arg) { + $CONF{"OUTPUT"} =~ s/\.gz$// if $LOGFILES[0]->{"type"} eq TYPE_GZIP; + $CONF{"OUTPUT"} =~ s/\.bz2$// if $LOGFILES[0]->{"type"} eq TYPE_BZIP2; + } + die "$THIS_FILE: Please specify output prefix\n$SHORTHELP\n" + if !defined $CONF{"OUTPUT"}; + $CONF{"OUTPUT"} = rel2abs $CONF{"OUTPUT"}; + $_ = (fileparse $CONF{"OUTPUT"})[1]; + die "$THIS_FILE: $_: Not found\n$SHORTHELP\n" + if !-e $_; + die "$THIS_FILE: $_: Not a directory\n$SHORTHELP\n" + if !-d $_; + die "$THIS_FILE: $_: Permission denied\n$SHORTHELP\n" + if !-w $_; + + return; +} + +# whereis: Find an executable +# Code inspired from CPAN::FirstTime +sub whereis($) { + local ($_, %_); + my ($file, $path); + $file = $_[0]; + return $WHEREIS{$file} if exists $WHEREIS{$file}; + foreach my $dir (path) { + print STDERR " Checking $dir ... " if $VERBOSE > 3; + if (defined($path = MM->maybe_command(catfile($dir, $file)))) { + print STDERR "$path\n found " if $VERBOSE > 3; + return ($WHEREIS{$file} = $path); + } + print STDERR "no\n" if $VERBOSE > 3; + } + return ($WHEREIS{$file} = undef); +} + +# to_yyyymm: convert timestamp to yyyymm +sub to_yyyymm($) { + local ($_, %_); + @_ = localtime $_[0]; + return sprintf "%04d%02d", $_[5] + 1900, $_[4] + 1; +} + +# format_number: Format the number every 3 digit +sub format_number($) { + local $_; + $_ = $_[0]; + # Group every 3 digit + $_ = $1 . "," . $2 . $3 while /^([^\.]*\d)(\d\d\d)(.*)$/; + return $_; +} + +# rel2abs: Convert a relative path to an absolute path +sub rel2abs($;$) { + local ($_, %_); + my ($path, $base); + ($path, $base) = @_; + + # Turn the base absolute + $base = cwd unless defined $base; + $base = rel2abs $base if !file_name_is_absolute $base; + + # Deal with the ~ user home directories under UNIX + if (defined $Config::Config{"d_getpwent"}) { + @_ = splitdir($path); + # If it starts from the user home directory + if ($_[0] =~ /^~(.*)$/) { + my ($user, @pwent, $home); + $user = $1; + # The same as the current user + if ( (@pwent = getpwuid $>) > 0 + && ($user eq "" || $user eq $pwent[0])) { + # Replace with the user home directory + # Respect the HOME environment variable if exists + $home = exists $ENV{"HOME"}? $ENV{"HOME"}: $pwent[7]; + @_ = (splitdir($home), @_[1...$#_]); + # Get the user home directory + } elsif ((@pwent = getpwnam $user) > 0) { + # Replace with the user home directory + $home = $pwent[7]; + @_ = (splitdir($home), @_[1...$#_]); + } + # Compose the path + $path = catfile @_; + } + } + + # Append the current directory if relative + $path = catfile($base, $path) unless file_name_is_absolute $path; + + @_ = splitdir($path); # Split into directory components + # Add an empty filename level if last level is a directory + push @_, "" if ($_[@_-1] eq curdir || $_[@_-1] eq updir); + for ($_ = 1; $_ < @_; $_++) { # Parse each level one by one + # If it is this directory + if ($_[$_] eq curdir) { + splice @_, $_, 1; # Remove this level directly + $_--; # The level number drop by 1 + # If it is the parent directory + } elsif ($_ > 1 && $_[$_] eq updir && $_[$_-1] ne updir) { + splice @_, $_-1, 2; # Remove this and the previous level + $_ -= 2; # The level number drop by 2 + } + } + $path = catfile @_; # Compose the full path + return $path; +} + + +# _private::ProgressBar: The progress bar displayer +package _private::ProgressBar; +use 5.008; +use strict; +use warnings; + +# new: Initialize the progrss bar handler +sub new : method { + local ($_, %_); + my ($class, $self, $label, $total); + ($class, $label, $total) = @_; + $self = bless {}, $class; + $self->{"label"} = $label; + $self->{"total"} = $total; + $self->{"start"} = time; + $self->{"lastline"} = undef; + require Term::ReadKey; + return $self; +} + +# update: Update the progress bar +sub update : method { + local ($_, %_); + my ($self, $cur, $label, $width, $elapsed, $min, $sec, $bar, $line); + ($self, $cur, $label) = @_; + $label = $self->{"label"} if !defined $label; + + # Not enough space for a progress bar + return if ($width = (Term::ReadKey::GetTerminalSize())[0] - 30) < 1; + # Calculate the elapsed time + $elapsed = time - $self->{"start"}; + $sec = $elapsed % 60; + $min = ($elapsed - $sec) / 60; + # Calculate the percentage and the progress bar + $bar = "=" x sprintf("%1.0f", ($cur / $self->{"total"}) * $width); + # Compose the line + $line = sprintf "\r%-14.14s [%-".$width."s] %3.0f%% %02d:%02d", + $label, $bar, ($cur / $self->{"total"}) * 100, $min, $sec; + # Print if changed + if (!defined $self->{"lastline"} || $self->{"lastline"} ne $line) { + # Print it + print STDERR "\r$line"; + # Record the current line + $self->{"lastline"} = $line; + } + # Finished + print STDERR "\n" if $cur == $self->{"total"}; + return; +} + + +# _private::LogFile: The source log file +package _private::LogFile; +use 5.008; +use strict; +use warnings; +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); +use File::Basename qw(fileparse); +use File::Temp qw(tempfile); + +# Constants +# The file type checkers +use constant MAGIC_PM => "File::MMagic"; +use constant MAGIC_EXEC => "file"; +use constant MAGIC_SUFFIX => "suffix"; + +use vars qw($MAGIC_METHOD $MAGIC); +BEGIN { +undef $MAGIC_METHOD; +undef $MAGIC; +} + +# new: Initialize the source log file processer +sub new : method { + local ($_, %_); + my ($class, $self, $file, $FH, $f0); + ($class, $file) = @_; + + # STDIN is another class + if ($file eq "-") { + $class .= "::STDIN"; + return $class->new(@_[1...$#_]); + } + + $self = bless {}, $class; + $self->{"stdin"} = 0; + $self->{"keep"} = $CONF{"KEEP"}; + $self->{"override"} = $CONF{"OVERRIDE"}; + $self->{"tmp"} = undef; + + # Load the File::MMagic first before opening anything, or the seek + # method will not be loaded into IO::Handle + $self->check_magic; + $self->{"checktype"} = $file if $MAGIC_METHOD eq MAGIC_EXEC; + + $self->{"file"} = rel2abs $file; + ($f0, $file) = ($file, $self->{"file"}); + # Open the file + if ($self->{"keep"} eq KEEP_ALL) { + open $FH, $file or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_SH; + } else { + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + } + $self->{"FH"} = $FH; + + # Check the file type + print STDERR "Checking file type of $f0 ... " if $VERBOSE > 1; + $self->{"type"} = $self->check_type; + print STDERR $self->{"type"} . "\n" if $VERBOSE > 1; + # Check the I/O handler to use + $self->{"io"} = $self->check_io; + # Open the file + $self->{"io"}->open_read($file, $self->{"FH"}); + # Check the log file fromat + $self->{"format"} = $self->check_format; + # Not empty + if (!$self->{"is_empty"}) { + # Check the temporarily working file availability + $self->{"temp"} = $self->check_temp; + } + + return $self; +} + +# check_temp: Check the temporarily working file availability +sub check_temp : method { + local ($_, %_); + my ($self, $file, $dir, $suf); + $self = $_[0]; + + # No need to create a named temporarily file if we keep the log file + if ($CONF{"KEEP"} eq KEEP_ALL) { + # Create an anonymous temporary file + return undef; + } + + if ($self->{"type"} eq TYPE_GZIP) { + ($file, $dir, $suf) = fileparse $self->{"file"}, ".gz"; + } elsif ($self->{"type"} eq TYPE_BZIP2) { + ($file, $dir, $suf) = fileparse $self->{"file"}, ".bz2"; + } else { + ($file, $dir, $suf) = fileparse $self->{"file"}; + } + + $_ = $dir . $file . TMP_SUFFIX; + # Does the temporary working file exists? + die "$THIS_FILE: $_: Temporary working file exists\n$SHORTHELP\n" + if -e $_; + + # Check if we can create the temporarily working file + die "$THIS_FILE: $dir: File exists\n$SHORTHELP\n" + if !-e $dir; + die "$THIS_FILE: $dir: Not a directory\n$SHORTHELP\n" + if !-d $dir; + die "$THIS_FILE: $dir: Permission denied\n$SHORTHELP\n" + if !-w $dir; + + return $_; +} + +# check_format: Check the log file fromat +sub check_format : method { + local ($_, %_); + my $self; + $self = $_[0]; + + # Read the first line from the source file + $self->{"first_line"} = $self->{"io"}->readline; + # Skip empty files + $self->{"is_empty"} = !defined $self->{"first_line"}; + if ($self->{"is_empty"}) { + print STDERR "File is empty.\n" if $VERBOSE > 1; + return undef; + } + + # Check the log file format + print STDERR "Checking the log file format... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + $_ = _private::Format->check_format($self->{"first_line"}); + # Unrecognized log record + if (!defined $_) { + print STDERR "unknown\n" if $VERBOSE > 1; + die "$THIS_FILE: Unrecognized log file format"; + } + print STDERR "$_\n" if $VERBOSE > 1; + return $_; +} + +# create_temp: Create the temporary working file +sub create_temp : method { + local ($_, %_); + my ($self, $temp, $FHT); + $self = $_[0]; + + # Create a named temporarily working file + if (defined $self->{"temp"}) { + $temp = $self->{"temp"}; + print STDERR "Creating $temp ... " if $VERBOSE > 2; + open $FHT, "+>", $temp or die "$THIS_FILE: $temp: $!"; + flock $FHT, LOCK_EX; + $self->{"FHT"} = $FHT; + print STDERR "done\n" if $VERBOSE > 2; + return $FHT; + + # Create an anonymous temporarily working file + } else { + print STDERR "Creating temporary working file for " . $self->{"file"} . " ... " + if $VERBOSE > 2; + $self->{"FHT"} = tempfile or die "$THIS_FILE: tempfile: $!"; + flock $self->{"FHT"}, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + return $self->{"FHT"}; + } +} + +# remove_temp: Remove the temporary working file +sub remove_temp : method { + local ($_, %_); + my ($self, $temp, $FHT); + $self = $_[0]; + ($FHT, $temp) = ($self->{"FHT"}, $self->{"temp"}); + # A named temporarily file + if (defined $self->{"temp"}) { + print STDERR "Removing $temp ... " if $VERBOSE > 2; + close $FHT or die "$THIS_FILE: $temp: $!"; + unlink $temp or die "$THIS_FILE: $temp: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # An anonymous temporarily working file + } else { + print STDERR "Closing temporary working file ... " if $VERBOSE > 2; + close $FHT or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + return; +} + +# read_source: Read the source file +sub read_source : method { + local ($_, %_); + my ($self, $file, $FHT, $count); + $self = $_[0]; + ($file, $FHT) = ($self->{"file"}, $self->{"FHT"}); + print STDERR "Reading from $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + print STDERR " Reading source records ... " if $VERBOSE > 2; + $count = 0; + # The first line is already read, to determine the format + $_ = $self->{"first_line"}; + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + $count++; + # The rest lines + while (defined($_ = $self->{"io"}->readline)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + $self->{"io"}->close($self->{"keep"}, $self->{"tmp"}); + print STDERR "$count records\n" if $VERBOSE > 1; + $self->{"count"} = $count; + return $count;; +} + +# read_record: Read a record, returning the record and its month +sub read_record : method { + local ($_, %_); + my ($self, $FHT, $record, $month); + $self = $_[0]; + $FHT = $self->{"FHT"}; + # Reset when start reading + if (!exists $self->{"reading_record"}) { + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + $self->{"reading_record"} = 1; + } + $_ = <$FHT>; + # End of read + delete $self->{"reading_record"} if !defined $_; + return $_; +} + +# save_this_month: Save the records of this month +sub save_this_month : method { + local ($_, %_); + my ($self, $record, $FH); + ($self, $record) = @_; + # Create the temporary saving space + if (!exists $self->{"FHTH"}) { + print STDERR "\n" if $VERBOSE > 2 && defined $PROGBAR; + print STDERR " Creating buffer for this month ... " + if $VERBOSE > 2; + $FH = tempfile or die "$THIS_FILE: tempfile: $!"; + flock $FH, LOCK_EX or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + $self->{"FHTH"} = $FH; + $self->{"count_thismonth"} = 0; + $self->{"size_thismonth"} = 0; + } else { + $FH = $self->{"FHTH"}; + } + # Save the record + print $FH $record or die "$THIS_FILE: tempfile: $!"; + $self->{"count_thismonth"}++; + $self->{"size_thismonth"} += length $record; + return; +} + +# restore_this_month: Return the records of this month to the log file +sub restore_this_month : method { + local ($_, %_); + my ($self, $file, $FH, $count); + $self = $_[0]; + # Bounce if no record to restore + return unless exists $self->{"FHTH"}; + ($file, $FH) = ($self->{"file"}, $self->{"FHTH"}); + + # Prepend the records using the I/O class implementation + ref($self->{"io"})->prepend_records($file, $FH); + + # Report the statistics + printf STDERR "%s: keeping %s records, %s bytes\n", + $file, format_number($self->{"count_thismonth"}), + format_number($self->{"size_thismonth"}) + if $VERBOSE > 0; + + return; +} + +# check_type: Check the source file type +sub check_type : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + $self = $_[0]; + ($file, $FH) = ($self->{"file"}, $self->{"FH"}); + + # Check the file type checker to use + $self->check_magic; + die "$THIS_FILE: Cannot check STDIN from the filename suffix.\n" + if $self->{"stdin"} && $MAGIC_METHOD eq MAGIC_SUFFIX; + + # Check by file name suffix + # Check by file name suffix on empty files, too. + # Compress::Bzip2 2 creates empty files that confuses further processing. + if (-z $FH || $MAGIC_METHOD eq MAGIC_SUFFIX) { + return TYPE_GZIP if $file =~ /\.gz$/; + return TYPE_BZIP2 if $file =~ /\.bz2$/; + # Otherwise we assume it to be text/plain + return TYPE_PLAIN; + } + + # Check the file format + # Check by File::MMagic + if ($MAGIC_METHOD eq MAGIC_PM) { + $_ = $MAGIC->checktype_filehandle($FH); + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + + # Check by the file program + } elsif ($MAGIC_METHOD eq MAGIC_EXEC) { + flock $FH, LOCK_UN; + @_ = ($MAGIC, $self->{"checktype"}); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "$CMD |" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "-|", @_ or die "$THIS_FILE: $CMD: $!"; + } + $_ = join "", <$PH>; + close $PH or die "$THIS_FILE: $CMD: $!"; + if ($self->{"keep"} eq KEEP_ALL) { + flock $FH, LOCK_SH; + } else { + flock $FH, LOCK_EX; + } + } + + # Check the returned file type text + return TYPE_GZIP if /gzip/i; + return TYPE_BZIP2 if /bzip2/i; + # Default everything to text/plain + return TYPE_PLAIN; +} + +# check_io: Check the I/O handler to use +sub check_io : method { + local ($_, %_); + my $self; + $self = $_[0]; + # We need a gzip compression I/O handler + return _private::IO->check_gzip if $self->{"type"} eq TYPE_GZIP; + # We need a bzip2 compression I/O handler + return _private::IO->check_bzip2 if $self->{"type"} eq TYPE_BZIP2; + # We need a plain I/O handler + return _private::IO::Plain->new; +} + +# check_magic: Check the file type checker to use +sub check_magic : method { + local ($_, %_); + my $self; + $self = $_[0]; + + # Checked before + return $MAGIC_METHOD if defined $MAGIC_METHOD; + + print STDERR "Checking file type checker to use ... " if $VERBOSE > 1; + print STDERR "\n Checking File::MMagic ... " if $VERBOSE > 2; + # Check if we have File::MMagic + if (eval { require File::MMagic; 1; }) { + print STDERR "OK\nfound " if $VERBOSE > 2; + print STDERR "File::MMagic\n" if $VERBOSE > 1; + $MAGIC = File::MMagic->new; + return ($MAGIC_METHOD = MAGIC_PM); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + $@ =~ s/^(Can't locate \S+ in \@INC).*\n/$1\n/; # ' + warn "$@" if $VERBOSE == 1; + + # Looking for file from PATH + print STDERR " Checking file ... " if $VERBOSE > 2; + # Found in PATH + if (defined($MAGIC = whereis "file")) { + print STDERR "$MAGIC\nfound " if $VERBOSE > 2; + print STDERR "$MAGIC\n" if $VERBOSE > 1; + warn "$THIS_FILE: We will check with $MAGIC instead\n" + if $VERBOSE > 0; + return ($MAGIC_METHOD = MAGIC_EXEC); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + + # Check by file name suffix + print STDERR " Fall back using file name suffix instead\n" if $VERBOSE > 2; + print STDERR "file name suffix\n" if $VERBOSE > 1; + warn "$THIS_FILE: We will check by file name suffix instead\n" + if $VERBOSE == 1; + return ($MAGIC_METHOD = MAGIC_SUFFIX); +} + + +# _private::LogFile::STDIN: The source log file as STDIN +package _private::LogFile::STDIN; +use 5.008; +use strict; +use warnings; +use base qw(_private::LogFile); +BEGIN { +import main; +} + +use IO::Handle; +use Fcntl qw(:flock :seek); +use File::Temp qw(tempfile unlink0); + +# new: Initialize the source log file processer +sub new : method { + local ($_, %_); + my ($class, $self, $file, $FH, $tmp); + ($class, $file) = @_; + + # We only initialize STDIN + return $file if ref($file) ne "" || $file ne "-"; + + $self = bless {}, $class; + $self->{"stdin"} = 1; + $self->{"keep"} = KEEP_ALL; + $self->{"override"} = OVERRIDE_OVERWRITE; + $self->{"tmp"} = undef; + + # Load the File::MMagic first before opening anything, or the seek + # method will not be loaded into IO::Handle + $self->check_magic; + + # Save STDIN to somewhere + $file = "the STDIN buffer"; + if ($_private::LogFile::MAGIC_METHOD eq _private::LogFile::MAGIC_EXEC) { + ($FH, $tmp) = tempfile(undef, UNLINK => 1) + or die "$THIS_FILE: tempfile: $!"; + $self->{"checktype"} = $tmp; + $self->{"tmp"} = $tmp; + } else { + undef $tmp; + $FH = tempfile or die "$THIS_FILE: tempfile: $!"; + } + ($self->{"FH"}, $self->{"file"}) = ($FH, $file); + flock $FH, LOCK_EX; + print STDERR "Saving STDIN to a buffer ... " if $VERBOSE > 1; + while (defined($_ = )) { + print $FH $_ or die "$THIS_FILE: $file: $!"; + } + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 1; + + # Check the file type + print STDERR "Checking file type of STDIN ... " if $VERBOSE > 1; + $self->{"type"} = $self->check_type; + # Unlink after check_type() with file executable + if ($_private::LogFile::MAGIC_METHOD eq _private::LogFile::MAGIC_EXEC) { + unlink0($FH, $tmp) or die "$THIS_FILE: $tmp: $!"; + } + print STDERR $self->{"type"} . "\n" if $VERBOSE > 1; + # Check the I/O handler to use + $self->{"io"} = $self->check_io; + # Open the file + $self->{"io"}->open_read($file, $self->{"FH"}); + # Check the log file fromat + $self->{"format"} = $self->check_format; + # STDIN always goes to an anonymous temporarily working file + $self->{"temp"} = undef; + + return $self; +} + +# remove_temp: Remove the temporary working file +sub remove_temp : method { + local ($_, %_); + $_ = $_[0]; + print STDERR "Closing temporary working file for STDIN ... " if $VERBOSE > 2; + close $_->{"FHT"} or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + return; +} + + +# _private::Archive: The result archived log file +package _private::Archive; +use 5.008; +use strict; +use warnings; +BEGIN { +import main; +} + +use Date::Parse qw(str2time); +use Fcntl qw(:flock :seek); +use File::Basename qw(basename); +use File::Temp qw(tempfile); + +# new: Initialize the result archive file processer +sub new : method { + local ($_, %_); + my ($class, $self, $month, $file, $FH); + ($class, $month) = @_; + $self = bless {}, $class; + $self->{"month"} = $month; + $self->{"override"} = $CONF{"OVERRIDE"}; + $self->{"format"} = $CONF{"FORMAT"}; + if ($CONF{"COMPRESS"} eq COMPRESS_GZIP) { + $self->{"io"} = _private::IO->check_gzip; + } elsif ($CONF{"COMPRESS"} eq COMPRESS_BZIP2) { + $self->{"io"} = _private::IO->check_bzip2; + } else { + $self->{"io"} = _private::IO::Plain->new; + } + # The resulted output file + $self->{"file"} = $CONF{"OUTPUT"} . "." . $month + . $self->{"io"}->suffix; + $file = $self->{"file"}; + $self->{"ignore"} = 0; + # The resulted output file exists + if (-e $file) { + # If we should ask + # Jump off the progress bar + print STDERR "\n" + if $self->{"override"} eq OVERRIDE_ASK && defined $PROGBAR; + while ($self->{"override"} eq OVERRIDE_ASK) { + printf STDERR "$file exists, (O)verwrite, (A)ppend, (I)gnore, (F)ail? [F] "; + $_ = ; + # Fail if not answered + if (!defined $_) { + print STDERR "\nArhh.. you are not here. I had better drop it right now.\n"; + $self->{"override"} = OVERRIDE_FAIL; + last; + } + chomp; + # Overwrite + if (lc $_ eq "o" || lc $_ eq "overwrite") { + $self->{"override"} = OVERRIDE_OVERWRITE; + # Append + } elsif (lc $_ eq "a" || lc $_ eq "append") { + $self->{"override"} = OVERRIDE_APPEND; + # Ignore + } elsif (lc $_ eq "i" || lc $_ eq "ignore") { + $self->{"override"} = OVERRIDE_IGNORE; + # Fail + } elsif (lc $_ eq "f" || lc $_ eq "fail" || lc $_ eq "") { + $self->{"override"} = OVERRIDE_FAIL; + # Else, ask again + } else { + print STDERR "What?\n"; + $self->{"override"} = OVERRIDE_ASK; + } + } + # Overwrite or append + if ( $self->{"override"} eq OVERRIDE_OVERWRITE + || $self->{"override"} eq OVERRIDE_APPEND) { + # OK + } elsif ($self->{"override"} eq OVERRIDE_IGNORE) { + $self->{"ignore"} = 1; + } elsif ($self->{"override"} eq OVERRIDE_FAIL) { + die "$THIS_FILE: $file: Output file exists\n"; + } + + # Not exists - we always create it + } else { + $self->{"override"} = OVERRIDE_OVERWRITE; + } + # The temporary log record backet + if (!$self->{"ignore"}) { + print STDERR "\n" if $VERBOSE > 2 && defined $PROGBAR; + print STDERR " Creating buffer for $month ... " + if $VERBOSE > 2; + $FH = tempfile or die "$THIS_FILE: tempfile: $!"; + flock $FH, LOCK_EX or die "$THIS_FILE: tempfile: $!"; + $self->{"FH"} = $FH; + print STDERR "done\n" if $VERBOSE > 2; + } + $self->{"sizeorig"} = 0; + return $self; +} + +# add: Add a record to the temporarily archive file +sub add : method { + local ($_, %_); + my ($self, $FH); + ($self, $_) = @_; + $FH = $self->{"FH"}; + print $FH $_ or die "$THIS_FILE: tempfile: $!"; + $self->{"sizeorig"} += length $_; + return; +} + +# sort: Sort the records +sub sort : method { + local ($_, %_); + my ($self, $FH0, $FH1, $month, $count, $pos, $t, @recs); + $self = $_[0]; + ($FH0, $month) = ($self->{"FH"}, $self->{"month"}); + + print STDERR "Sorting records of $month ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + + # Obtain the information of each record + print STDERR " Obtain the time and position of the records ... " + if $VERBOSE > 2; + seek $FH0, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + @recs = qw(); + ($pos = tell $FH0) != -1 or die "$THIS_FILE: tempfile: $!"; + $count = 0; + while (defined($_ = <$FH0>)) { + $t = str2time($self->{"format"}->match($_)); + push @recs, { "pos" => $pos, "time" => $t }; + $count++; + ($pos = tell $FH0) != -1 or die "$THIS_FILE: tempfile: $!"; + } + print STDERR "$count records\n" if $VERBOSE > 2; + + # Sort by time and then original order + print STDERR " Sorting the records by time ... " if $VERBOSE > 2; + @recs = CORE::sort { $$a{"time"} <=> $$b{"time"} + || $$a{"pos"} <=> $$b{"pos"} } @recs; + print STDERR "done\n" if $VERBOSE > 2; + + # Store the records according to the new order + print STDERR " Creating new buffer for $month ... " if $VERBOSE > 2; + $FH1 = tempfile or die "$THIS_FILE: tempfile: $!"; + flock $FH1, LOCK_EX or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Storing sorted records to the new buffer ... " + if $VERBOSE > 2; + $count = 0; + foreach my $r (@recs) { + seek $FH0, $$r{"pos"}, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + $_ = <$FH0>; + print $FH1 $_ or die "$THIS_FILE: tempfile: $!"; + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + + # Use the new buffer instead of the old one + print STDERR " Switching to the new buffer ... " if $VERBOSE > 2; + flock $FH0, LOCK_UN or die "$THIS_FILE: tempfile: $!"; + close $FH0 or die "$THIS_FILE: tempfile: $!"; + $self->{"FH"} = $FH1; + print STDERR "done\n" if $VERBOSE > 2; + + print STDERR "$count records\n" if $VERBOSE > 1; + return; +} + +# store_archive: Store the archived log records +sub store_archive : method { + local ($_, %_); + my ($self, $FH, $file, $count); + $self = $_[0]; + ($FH, $file) = ($self->{"FH"}, $self->{"file"}); + # Reset the file reader + seek $FH, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + # Overwrite + if ($self->{"override"} eq OVERRIDE_OVERWRITE) { + print STDERR "Outputing to $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + $self->{"io"}->open_write($file); + # Append + } elsif ($self->{"override"} eq OVERRIDE_APPEND) { + print STDERR "Appending to $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + $self->{"sizecomp"} = (stat $file)[7]; + $self->{"io"}->open_append($file); + } + # Copy the data to the archive file + print STDERR " Outputing records ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$FH>)) { + $self->{"io"}->write($_); + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + $self->{"io"}->close; + print STDERR "$count records\n" if $VERBOSE > 1; + # Report the statistics + # Overwrite + if ($self->{"override"} eq OVERRIDE_OVERWRITE) { + $self->{"sizecomp"} = (stat $file)[7]; + printf STDERR "%s: writing %s records, %s bytes, %s bytes, %0.2f%%\n", + $self->{"month"}, format_number($count), + format_number($self->{"sizeorig"}), + format_number($self->{"sizecomp"}), + ($self->{"sizecomp"}*100/$self->{"sizeorig"}) + if $VERBOSE > 0; + + # Append + } elsif ($self->{"override"} eq OVERRIDE_APPEND) { + $self->{"sizecomp"} = (stat $file)[7] - $self->{"sizecomp"}; + printf STDERR "%s: adding %s records, %s bytes, %s bytes, %0.2f%%\n", + $self->{"month"}, format_number($count), + format_number($self->{"sizeorig"}), + format_number($self->{"sizecomp"}), + ($self->{"sizecomp"}*100/$self->{"sizeorig"}) + if $VERBOSE > 0; + } + return; +} + +# _private::IO: The abstract I/O handler interface +package _private::IO; +use 5.008; +use strict; +use warnings; +BEGIN { +import main; +} + +use Fcntl qw(:seek); + +use vars qw($GZIP_IO $BZIP2_IO); +BEGIN { +undef $GZIP_IO; +undef $BZIP2_IO; +} + +# new: Initialize the I/O handler interface +sub new : method { bless {}, $_[0]; } + +# suffix: The file name suffix of this mime type +sub suffix : method { ""; } + +# check_gzip: Check for compression method of gzip +sub check_gzip : method { + local ($_, %_); + + # Checked before + return ref($GZIP_IO)->new if defined $GZIP_IO; + + # See whether Compress::Zlib or gzip + print STDERR "Checking gzip I/O handler to use ... " if $VERBOSE > 1; + print STDERR "\n Checking Compress::Zlib ... " if $VERBOSE > 2; + # Check if we have Compress::Zlib + if (eval { require Compress::Zlib; 1; }) { + print STDERR "OK\nfound " if $VERBOSE > 2; + print STDERR "Compress::Zlib\n" if $VERBOSE > 1; + return ($GZIP_IO = _private::IO::Gzip::PM->new); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + # It's OK not to warn + + # Looking for gzip from PATH + print STDERR " Checking gzip... " if $VERBOSE > 2; + # Found in PATH + if (defined($_ = whereis "gzip")) { + print STDERR "$_\nfound " if $VERBOSE > 2; + print STDERR "$_\n" if $VERBOSE > 1; + return ($GZIP_IO = _private::IO::Gzip::Exec->new); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + + print STDERR "not found\n" if $VERBOSE > 1; + die "$THIS_FILE: Necessary Compress::Zlib or gzip not available.\n$SHORTHELP\n"; +} + +# check_bzip2: Check for compression method of bzip2 +sub check_bzip2 : method { + local ($_, %_); + + # Checked before + return ref($BZIP2_IO)->new if defined $BZIP2_IO; + + # See whether Compress::Bzip2 or bzip2 + print STDERR "Checking bzip2 I/O handler to use ... " if $VERBOSE > 1; + print STDERR "\n Checking Compress::Bzip2 ... " if $VERBOSE > 2; + # Check if we have Compress::Bzip2 + if (eval { require Compress::Bzip2; import Compress::Bzip2 2.00; 1; }) { + print STDERR "OK\nfound " if $VERBOSE > 2; + print STDERR "Compress::Bzip2\n" if $VERBOSE > 1; + return ($BZIP2_IO = _private::IO::Bzip2::PM->new); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + # It's OK not to warn + + # Looking for bzip2 from PATH + print STDERR " Checking bzip2... " if $VERBOSE > 2; + # Found in PATH + if (defined($_ = whereis "bzip2")) { + print STDERR "$_\nfound " if $VERBOSE > 2; + print STDERR "$_\n" if $VERBOSE > 1; + return ($BZIP2_IO = _private::IO::Bzip2::Exec->new); + } + # Not found + print STDERR "no\n" if $VERBOSE > 2; + + print STDERR "not found\n" if $VERBOSE > 1; + die "$THIS_FILE: Necessary Compress::Bzip2 or bzip2 not available.\n$SHORTHELP\n"; +} + +# prepend_records: Prepend records to an existing file +# * static method * +# For most I/O we read records out and write back with 2 I/O accesses. +# But for plain text we need only open the file once. +# This implementation is for most I/O. Plain text implement this itself. +sub prepend_records : method { + local ($_, %_); + my ($class, $file, $FHT, $io, $count); + ($class, $file, $FHT) = @_; + + # Read the current records (added after program execution) + $io = $class->new; + print STDERR "Reading new records from $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + $io->open_read($file); + print STDERR " Reading new records ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = $io->readline)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + $io->close; + print STDERR "$count records\n" if $VERBOSE > 1; + + # Returing all the records + # Start a new I/O handler of the same class + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + $io = $class->new; + print STDERR "Returning all records to $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + $io->open_write($file); + print STDERR " Outputing records ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$FHT>)) { + $io->write($_); + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + $io->close; + print STDERR "$count records\n" if $VERBOSE > 1; + + return; +} + + +# _private::IO::Plain: The plain I/O handler +package _private::IO::Plain; +use 5.008; +use strict; +use warnings; +use base qw(_private::IO); +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); + +# open_read: Open the file for reading +sub open_read : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + return; +} + +# open_write: Open the file for writing +sub open_write : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Creating file in write mode ... " if $VERBOSE > 2; + open $FH, "+>", $file or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + return; +} + +# open_append: Open the file for appending +sub open_append : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in append mode ... " if $VERBOSE > 2; + open $FH, ">>", $file or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + return; +} + +# readline: Read a line from the I/O stream +sub readline : method { + local ($_, %_); + my ($self, $FH); + $self = $_[0]; + $FH = $self->{"FH"}; + return <$FH>; +} + +# write: Output data to the I/O stream +sub write : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $_) = @_; + ($file, $FH) = ($self->{"file"}, $self->{"FH"}); + print $FH $_ or die "$THIS_FILE: $file: $!"; + return; +} + +# close: Close the I/O stream +sub close : method { + local ($_, %_); + my ($self, $keep, $tmp, $file, $FH); + ($self, $keep, $tmp) = @_; + $keep = KEEP_ALL if @_ < 2; + ($file, $FH) = ($self->{"file"}, $self->{"FH"}); + + # Restart the file + if ($keep eq KEEP_RESTART || $keep eq KEEP_THISMONTH) { + # Empty the source file + print STDERR " Emptying file ... " if $VERBOSE > 2; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + CORE::close $FH or die "$THIS_FILE: $file: $!"; + delete $self->{"FH"}; + delete $self->{"file"}; + + # Delete the file + if ($keep eq KEEP_DELETE) { + print STDERR " Deleting file ... " if $VERBOSE > 2; + unlink $file or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + # Delete the temporary file if needed + if (defined $tmp && -e $tmp) { + unlink $tmp or die "$THIS_FILE: $tmp: $!"; + } + return; +} + +# prepend_records: Prepend records to an existing file +# * static method * +# Plain text version that only open the file once +sub prepend_records : method { + local ($_, %_); + my ($class, $file, $FHT, $FHC, $count); + ($class, $file, $FHT) = @_; + + # Read the current records (added after program execution) + print STDERR "Reading new records from $file ... " if $VERBOSE > 1; + print STDERR "\n" if $VERBOSE > 2; + + print STDERR " Opening file in read/write mode ... " if $VERBOSE > 2; + open $FHC, "+<", $file or die "$THIS_FILE: $file: $!"; + flock $FHC, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + + # Read the new records + print STDERR " Reading new records ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$FHC>)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + + # Reset the reader/writer + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + seek $FHC, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FHC, 0 or die "$THIS_FILE: $file: $!"; + + # Return all the records + print STDERR " Outputing records ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$FHT>)) { + print $FHC $_ or die "$THIS_FILE: $file: $!"; + $count++; + } + print STDERR "$count records\n" if $VERBOSE > 2; + + CORE::close $FHC or die "$THIS_FILE: $file: $!"; + print STDERR "$count records\n" if $VERBOSE > 1; + + return; +} + + +# _private::IO::Gzip::PM: The gzip module compression I/O handler +package _private::IO::Gzip::PM; +use 5.008; +use strict; +use warnings; +use base qw(_private::IO); +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); +use File::Temp qw(tempfile); + +# suffix: The file name suffix of this mime type +sub suffix : method { ".gz"; } + +# open_read: Open the file for reading +sub open_read : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Zlib qw(gzopen); + print STDERR " Attaching file with gzopen(..., \"rb\") ... " if $VERBOSE > 2; + $self->{"gz"} = gzopen($FH, "rb") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + return; +} + +# open_write: Open the file for writing +sub open_write : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Creating file in write mode ... " if $VERBOSE > 2; + open $FH, "+>", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Zlib qw(gzopen); + print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $self->{"gz"} = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + return; +} + +# open_append: Open the file for appending +sub open_append : method { + local ($_, %_); + my ($self, $file, $FH, $gz); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read/write mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Zlib qw(gzopen); + + # Save the original data if file has content so that file size is + # greater than 0. STDOUT is always of size 0. + if ((stat $FH)[7] > 0) { + my ($count, $FHT, $gzt, $n); + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + # Copy the original content to a buffer + print STDERR " Reading compressed data to the buffer ... " if $VERBOSE > 2; + $FHT = tempfile or die "$THIS_FILE: tempfile: $!"; + while (defined($_ = <$FH>)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + } + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Restarting file ... " if $VERBOSE > 2; + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Decompress the buffer and save to our file + print STDERR " Attaching buffer with gzopen(..., \"rb\") ... " if $VERBOSE > 2; + $gzt = gzopen($FHT, "rb") or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $gz = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2; + $count = 0; + while (($n = $gzt->gzreadline($_)) != 0) { + die "$THIS_FILE: tempfile: " . $gz->gzerror if $n == -1; + ($gz->gzwrite($_) == $n) or die "$THIS_FILE: $file: " . $gz->gzerror; + $count++; + } + close $FHT or die "$THIS_FILE: tempfile: $!"; + print STDERR "$count records\n" if $VERBOSE > 2; + + # A whole new file + } else { + print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $gz = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + $self->{"gz"} = $gz; + return; +} + +# readline: Read a line from the I/O stream +sub readline : method { + local ($_, %_); + my ($self, $file, $gz, $n); + $self = $_[0]; + ($file, $gz) = ($self->{"file"}, $self->{"gz"}); + (($n = $gz->gzreadline($_)) != -1) or die "$THIS_FILE: $file: " . $gz->gzerror; + return undef if $n == 0; + return $_; +} + +# write: Output data to the I/O stream +sub write : method { + local ($_, %_); + my ($self, $file, $gz); + ($self, $_) = @_; + ($file, $gz) = ($self->{"file"}, $self->{"gz"}); + ($gz->gzwrite($_) == length $_) or die "$THIS_FILE: $file: " . $gz->gzerror; + return; +} + +# close: Close the I/O stream +sub close : method { + local ($_, %_); + my ($self, $keep, $tmp, $file, $FH, $gz); + ($self, $keep, $tmp) = @_; + $keep = KEEP_ALL if @_ < 2; + ($file, $FH, $gz) = ($self->{"file"}, $self->{"FH"}, $self->{"gz"}); + + # Restart the file + if ($keep eq KEEP_RESTART || $keep eq KEEP_THISMONTH) { + # Empty the source file + print STDERR " Emptying file ... " if $VERBOSE > 2; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Create empty compressed content + print STDERR " Applying empty compressed content ... " if $VERBOSE > 2; + $_ = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + $_->gzclose and die "$THIS_FILE: $file: " . $_->gzerror; + undef $_; + undef $gz; + print STDERR "done\n" if $VERBOSE > 2; + } + + if (defined $gz) { + $gz->gzclose and die "$THIS_FILE: $file: " . $gz->gzerror; + } + CORE::close $self->{"FH"} if $self->{"FH"}->opened; + delete $self->{"gz"}; + delete $self->{"FH"}; + delete $self->{"file"}; + + # Delete the file + if ($keep eq KEEP_DELETE) { + print STDERR " Deleting file ... " if $VERBOSE > 2; + unlink $file or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + # Delete the temporary file if needed + if (defined $tmp && -e $tmp) { + unlink $tmp or die "$THIS_FILE: $tmp: $!"; + } + return; +} + + +# _private::IO::Gzip::Exec: The gzip executable compression I/O handler +package _private::IO::Gzip::Exec; +use 5.008; +use strict; +use warnings; +use base qw(_private::IO); +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); +use File::Temp qw(tempfile); + +use vars qw($EXEC); +BEGIN { +undef $EXEC; +} + +# suffix: The file name suffix of this mime type +sub suffix : method { ".gz"; } + +# open_read: Open the file for reading +sub open_read : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "gzip" if !defined $EXEC; + + @_ = ($EXEC, "-cdf"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD from file ... " if $VERBOSE > 2; + # Redirect STDIN to $FH + open STDIN, "<&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "$CMD |" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "-|", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDIN + open STDIN, "<&", $STDIN or die "$THIS_FILE: STDIN: $!"; + print STDERR "done\n" if $VERBOSE > 2; + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# open_write: Open the file for writing +sub open_write : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Creating file in write mode ... " if $VERBOSE > 2; + open $FH, "+>", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "gzip" if !defined $EXEC; + + @_ = ($EXEC, "-c9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# open_append: Open the file for appending +sub open_append : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read/write mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "gzip" if !defined $EXEC; + + # Save the original data if file has content so that file size is + # greater than 0. STDOUT is always of size 0. + if ((stat $FH)[7] > 0) { + my ($count, $FHT, $PHT, $CMDT); + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + # Copy the original content to a buffer + print STDERR " Reading compressed data to the buffer ... " if $VERBOSE > 2; + $FHT = tempfile or die "$THIS_FILE: tempfile: $!"; + while (defined($_ = <$FH>)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + } + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Restarting file ... " if $VERBOSE > 2; + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Decompress the buffer and save to our file + @_ = ($EXEC, "-cdf"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMDT = join " ", @_; + print STDERR " Starting $CMDT from buffer ... " if $VERBOSE > 2; + # Redirect STDIN to $FH + open STDIN, "<&", $FHT or die "$THIS_FILE: tempfile: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PHT, "$CMDT |" or die "$THIS_FILE: $CMDT: $!"; + } else { + open $PHT, "-|", @_ or die "$THIS_FILE: $CMDT: $!"; + } + # Restore STDIN + open STDIN, "<&", $STDIN or die "$THIS_FILE: STDIN: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + @_ = ($EXEC, "-c9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$PHT>)) { + print $PH $_ or die "$THIS_FILE: $file: $!"; + $count++; + } + close $PHT or die "$THIS_FILE: $CMDT: $!"; + close $FHT or die "$THIS_FILE: tempfile: $!"; + print STDERR "$count records\n" if $VERBOSE > 2; + + # A whole new file + } else { + @_ = ($EXEC, "-c9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# readline: Read a line from the I/O stream +sub readline : method { + local ($_, %_); + my ($self, $PH); + $self = $_[0]; + $PH = $self->{"PH"}; + return <$PH>; +} + +# write: Output data to the I/O stream +sub write : method { + local ($_, %_); + my ($self, $CMD, $PH); + ($self, $_) = @_; + ($CMD, $PH) = (join(" ", @{$self->{"CMD"}}), $self->{"PH"}); + print $PH $_ or die "$THIS_FILE: $CMD: $!"; + return; +} + +# close: Close the I/O stream +sub close : method { + local ($_, %_); + my ($self, $keep, $tmp, $file, $FH, $CMD, $PH); + ($self, $keep, $tmp) = @_; + $keep = KEEP_ALL if @_ < 2; + ($file, $FH) = ($self->{"file"}, $self->{"FH"}); + + # Restart the file + if ($keep eq KEEP_RESTART || $keep eq KEEP_THISMONTH) { + # Empty the source file + print STDERR " Emptying file ... " if $VERBOSE > 2; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Create empty compressed content + print STDERR " Applying empty compressed content ... " if $VERBOSE > 2; + $EXEC = whereis "gzip" if !defined $EXEC; + @_ = ($EXEC, "-c9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process and end it + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + close $PH or die "$THIS_FILE: $CMD: $!"; + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + ($CMD, $PH) = (join(" ", @{$self->{"CMD"}}), $self->{"PH"}); + CORE::close $PH or die "$THIS_FILE: $CMD: $!"; + CORE::close $FH or die "$THIS_FILE: $file: $!"; + delete $self->{"PH"}; + delete $self->{"CMD"}; + delete $self->{"FH"}; + delete $self->{"file"}; + + # Delete the file + if ($keep eq KEEP_DELETE) { + print STDERR " Deleting file ... " if $VERBOSE > 2; + unlink $file or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + # Delete the temporary file if needed + if (defined $tmp && -e $tmp) { + unlink $tmp or die "$THIS_FILE: $tmp: $!"; + } + return; +} + + +# _private::IO::Bzip2::PM: The bzip2 module compression I/O handler +package _private::IO::Bzip2::PM; +use 5.008; +use strict; +use warnings; +use base qw(_private::IO); +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); +use File::Temp qw(tempfile); + +# suffix: The file name suffix of this mime type +sub suffix : method { ".bz2"; } + +# open_read: Open the file for reading +sub open_read : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Bzip2 qw(bzopen); + print STDERR " Attaching file with bzopen(..., \"rb\") ... " if $VERBOSE > 2; + $self->{"bz"} = bzopen($FH, "rb") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + return; +} + +# open_write: Open the file for writing +sub open_write : method { + local ($_, %_); + my ($self, $file, $FH); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Creating file in write mode ... " if $VERBOSE > 2; + open $FH, "+>", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Bzip2 qw(bzopen); + print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $self->{"bz"} = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + return; +} + +# open_append: Open the file for appending +sub open_append : method { + local ($_, %_); + my ($self, $file, $FH, $bz); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read/write mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + flock $FH, LOCK_EX; + print STDERR "done\n" if $VERBOSE > 2; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + import Compress::Bzip2 qw(bzopen); + + # Save the original data if file has content so that file size is + # greater than 0. STDOUT is always of size 0. + if ((stat $FH)[7] > 0) { + my ($count, $FHT, $bzt, $n); + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + # Copy the original content to a buffer + print STDERR " Reading compressed data to the buffer ... " if $VERBOSE > 2; + $FHT = tempfile or die "$THIS_FILE: tempfile: $!"; + while (defined($_ = <$FH>)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + } + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Restarting file ... " if $VERBOSE > 2; + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Decompress the buffer and save to our file + print STDERR " Attaching buffer with bzopen(..., \"rb\") ... " if $VERBOSE > 2; + $bzt = bzopen($FHT, "rb") or die "$THIS_FILE: tempfile: $!"; + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $bz = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2; + $count = 0; + while (($n = $bzt->bzreadline($_)) != 0) { + die "$THIS_FILE: tempfile: " . $bz->bzerror if $n == -1; + ($bz->bzwrite($_, length $_) == length $_) + or die "$THIS_FILE: $file: " . $bz->bzerror; + $count++; + } + close $FHT or die "$THIS_FILE: tempfile: $!"; + print STDERR "$count records\n" if $VERBOSE > 2; + + # A whole new file + } else { + print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2; + $bz = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + $self->{"bz"} = $bz; + return; +} + +# readline: Read a line from the I/O stream +sub readline : method { + local ($_, %_); + my ($self, $file, $bz, $n); + $self = $_[0]; + ($file, $bz) = ($self->{"file"}, $self->{"bz"}); + (($n = $bz->bzreadline($_)) != -1) or die "$THIS_FILE: $file: " . $bz->bzerror; + return undef if $n == 0; + return $_; +} + +# write: Output data to the I/O stream +sub write : method { + local ($_, %_); + my ($self, $file, $bz); + ($self, $_) = @_; + ($file, $bz) = ($self->{"file"}, $self->{"bz"}); + ($bz->bzwrite($_, length $_) == length $_) + or die "$THIS_FILE: $file: " . $bz->bzerror; + return; +} + +# close: Close the I/O stream +sub close : method { + local ($_, %_); + my ($self, $keep, $tmp, $file, $FH, $bz); + ($self, $keep, $tmp) = @_; + $keep = KEEP_ALL if @_ < 2; + ($file, $FH, $bz) = ($self->{"file"}, $self->{"FH"}, $self->{"bz"}); + + # Restart the file + if ($keep eq KEEP_RESTART || $keep eq KEEP_THISMONTH) { + # Empty the source file + print STDERR " Emptying file ... " if $VERBOSE > 2; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Create empty compressed content + print STDERR " Applying empty compressed content ... " if $VERBOSE > 2; + $_ = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!"; + $_->bzclose and die "$THIS_FILE: $file: " . $_->bzerror; + undef $_; + undef $bz; + print STDERR "done\n" if $VERBOSE > 2; + } + + if (defined $bz) { + $bz->bzclose and die "$THIS_FILE: $file: " . $bz->bzerror; + } + CORE::close $self->{"FH"} if $self->{"FH"}->opened; + delete $self->{"bz"}; + delete $self->{"FH"}; + delete $self->{"file"}; + + # Delete the file + if ($keep eq KEEP_DELETE) { + print STDERR " Deleting file ... " if $VERBOSE > 2; + unlink $file or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + # Delete the temporary file if needed + if (defined $tmp && -e $tmp) { + unlink $tmp or die "$THIS_FILE: $tmp: $!"; + } + return; +} + + +# _private::IO::Bzip2::Exec: The bzip2 executable compression I/O handler +package _private::IO::Bzip2::Exec; +use 5.008; +use strict; +use warnings; +use base qw(_private::IO); +BEGIN { +import main; +} + +use Fcntl qw(:flock :seek); +use File::Temp qw(tempfile); + +use vars qw($EXEC); +BEGIN { +undef $EXEC; +} + +# suffix: The file name suffix of this mime type +sub suffix : method { ".bz2"; } + +# open_read: Open the file for reading +sub open_read : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "bzip2" if !defined $EXEC; + + @_ = ($EXEC, "-cdf"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD from file ... " if $VERBOSE > 2; + # Redirect STDIN to $FH + open STDIN, "<&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "$CMD |" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "-|", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDIN + open STDIN, "<&", $STDIN or die "$THIS_FILE: STDIN: $!"; + print STDERR "done\n" if $VERBOSE > 2; + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# open_write: Open the file for writing +sub open_write : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Creating file in write mode ... " if $VERBOSE > 2; + open $FH, "+>", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "bzip2" if !defined $EXEC; + + @_ = ($EXEC, "-9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# open_append: Open the file for appending +sub open_append : method { + local ($_, %_); + my ($self, $file, $FH, $PH, $CMD); + ($self, $file, $FH) = @_; + # Open the file if it is not opened yet + if (!defined $FH) { + print STDERR " Opening file in read/write mode ... " if $VERBOSE > 2; + open $FH, "+<", $file or die "$THIS_FILE: $file: $!"; + binmode $FH or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } else { + flock $FH, LOCK_UN; + } + ($self->{"file"}, $self->{"FH"}) = ($file, $FH); + $EXEC = whereis "bzip2" if !defined $EXEC; + + # Save the original data if file has content so that file size is + # greater than 0. STDOUT is always of size 0. + if ((stat $FH)[7] > 0) { + my ($count, $FHT, $PHT, $CMDT); + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + # Copy the original content to a buffer + print STDERR " Reading compressed data to the buffer ... " if $VERBOSE > 2; + $FHT = tempfile or die "$THIS_FILE: tempfile: $!"; + while (defined($_ = <$FH>)) { + print $FHT $_ or die "$THIS_FILE: tempfile: $!"; + } + print STDERR "done\n" if $VERBOSE > 2; + print STDERR " Restarting file ... " if $VERBOSE > 2; + seek $FHT, 0, SEEK_SET or die "$THIS_FILE: tempfile: $!"; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Decompress the buffer and save to our file + @_ = ($EXEC, "-cdf"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMDT = join " ", @_; + print STDERR " Starting $CMDT from buffer ... " if $VERBOSE > 2; + # Redirect STDIN to $FH + open STDIN, "<&", $FHT or die "$THIS_FILE: tempfile: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PHT, "$CMDT |" or die "$THIS_FILE: $CMDT: $!"; + } else { + open $PHT, "-|", @_ or die "$THIS_FILE: $CMDT: $!"; + } + # Restore STDIN + open STDIN, "<&", $STDIN or die "$THIS_FILE: STDIN: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + @_ = ($EXEC, "-9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2; + $count = 0; + while (defined($_ = <$PHT>)) { + print $PH $_ or die "$THIS_FILE: $file: $!"; + $count++; + } + close $PHT or die "$THIS_FILE: $CMDT: $!"; + close $FHT or die "$THIS_FILE: tempfile: $!"; + print STDERR "$count records\n" if $VERBOSE > 2; + + # A whole new file + } else { + @_ = ($EXEC, "-9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + print STDERR " Starting $CMD to file ... " if $VERBOSE > 2; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + ($self->{"CMD"}, $self->{"PH"}) = ([@_], $PH); + return; +} + +# readline: Read a line from the I/O stream +sub readline : method { + local ($_, %_); + my ($self, $PH); + $self = $_[0]; + $PH = $self->{"PH"}; + return <$PH>; +} + +# write: Output data to the I/O stream +sub write : method { + local ($_, %_); + my ($self, $CMD, $PH); + ($self, $_) = @_; + ($CMD, $PH) = (join(" ", @{$self->{"CMD"}}), $self->{"PH"}); + print $PH $_ or die "$THIS_FILE: $CMD: $!"; + return; +} + +# close: Close the I/O stream +sub close : method { + local ($_, %_); + my ($self, $keep, $tmp, $file, $FH, $CMD, $PH); + ($self, $keep, $tmp) = @_; + $keep = KEEP_ALL if @_ < 2; + ($file, $FH) = ($self->{"file"}, $self->{"FH"}); + + # Restart the file + if ($keep eq KEEP_RESTART || $keep eq KEEP_THISMONTH) { + my ($CMD, $PH); + # Empty the source file + print STDERR " Emptying file ... " if $VERBOSE > 2; + seek $FH, 0, SEEK_SET or die "$THIS_FILE: $file: $!"; + truncate $FH, 0 or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + + # Create empty compressed content + print STDERR " Applying empty compressed content ... " if $VERBOSE > 2; + $EXEC = whereis "bzip2" if !defined $EXEC; + @_ = ($EXEC, "-9f"); + @_ = map "\"$_\"", @_ if $^O eq "MSWin32"; + $CMD = join " ", @_; + # Redirect STDOUT to $FH + open STDOUT, ">&", $FH or die "$THIS_FILE: $file: $!"; + # Start the process and end it + if ($^O eq "MSWin32") { + open $PH, "| $CMD" or die "$THIS_FILE: $CMD: $!"; + } else { + open $PH, "|-", @_ or die "$THIS_FILE: $CMD: $!"; + } + close $PH or die "$THIS_FILE: $CMD: $!"; + # Restore STDOUT + open STDOUT, ">&", $STDOUT or die "$THIS_FILE: STDOUT: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + + ($CMD, $PH) = (join(" ", @{$self->{"CMD"}}), $self->{"PH"}); + CORE::close $PH or die "$THIS_FILE: $CMD: $!"; + CORE::close $FH or die "$THIS_FILE: $file: $!"; + delete $self->{"PH"}; + delete $self->{"CMD"}; + delete $self->{"FH"}; + delete $self->{"file"}; + + # Delete the file + if ($keep eq KEEP_DELETE) { + print STDERR " Deleting file ... " if $VERBOSE > 2; + unlink $file or die "$THIS_FILE: $file: $!"; + print STDERR "done\n" if $VERBOSE > 2; + } + # Delete the temporary file if needed + if (defined $tmp && -e $tmp) { + unlink $tmp or die "$THIS_FILE: $tmp: $!"; + } + return; +} + +# _private::Format: The abstract log file format handler interface +package _private::Format; +use 5.008; +use strict; +use warnings; +BEGIN { +import main; +} + +use Date::Parse qw(str2time); + +# new: Initialize the log record format parser +sub new : method { bless {}, $_[0]; } + +# check_format: Check the record format and return an appropriate parser +sub check_format : method { + local ($_, %_); + my (@fmts, $record); + $record = $_[1]; + @fmts = qw(_private::Format::Apache _private::Format::Syslog + _private::Format::NTP _private::Format::ApacheSSL + _private::Format::ModfISO); + foreach my $fmt (@fmts) { + $_ = $fmt->new; + print STDERR " Testing $_ ... " if $VERBOSE > 2; + if ($_->match($record)) { + print STDERR "match\n" if $VERBOSE > 2; + return $_; + } + print STDERR "not match\n" if $VERBOSE > 2; + } + return undef; +} + +# match: Try matching my format and return the matching date text +# Empty. Implement it in the subclasses. +sub match : method { return undef; } + +# parse_month: Parse the month of the log file +sub parse_month : method { + local ($_, %_); + my $self; + ($self, $_) = @_; + return undef unless defined($_ = $self->match($_)); + return undef unless defined($_ = str2time $_); + return to_yyyymm $_; +} + + +# _private::Format::Apache: The Apache log file format handler +package _private::Format::Apache; +use 5.008; +use strict; +use warnings; +use base qw(_private::Format); +use overload ("\"\"" => sub { "Apache acess_log"; }); + +# match: Try matching my format and return the matching date text +sub match : method { + return $_[1] =~ /^\S+ \S+ .*? \[(\d{2}\/[A-Z][a-z]{2}\/\d{4}:\d{2}:\d{2}:\d{2} [+\-]\d{4})\]/? + $1: undef; +} + + +# _private::Format::Syslog: The Syslog log file format handler +package _private::Format::Syslog; +use 5.008; +use strict; +use warnings; +use base qw(_private::Format); +use overload ("\"\"" => sub { "Syslog"; }); + +# match: Try matching my format and return the matching date text +sub match : method { + return $_[1] =~ /^([A-Z][a-z]{2} ?\d{1,2} \d{2}:\d{2}:\d{2}) /? + $1: undef; +} + + +# _private::Format::NTP: The NTP log file format handler +package _private::Format::NTP; +use 5.008; +use strict; +use warnings; +use base qw(_private::Format); +use overload ("\"\"" => sub { "NTP"; }); + +# match: Try matching my format and return the matching date text +sub match : method { + return $_[1] =~ /^( ?\d{1,2} [A-Z][a-z]{2} \d{2}:\d{2}:\d{2}) /? + $1: undef; +} + + +# _private::Format::ApacheSSL: The Apache ssl_engine_log log file format handler +package _private::Format::ApacheSSL; +use 5.008; +use strict; +use warnings; +use base qw(_private::Format); +use overload ("\"\"" => sub { "Apache SSL engine log"; }); + +# match: Try matching my format and return the matching date text +sub match : method { + return $_[1] =~ /^\[(\d{2}\/[A-Z][a-z]{2}\/\d{4} \d{2}:\d{2}:\d{2} )\d+\]/? + $1: undef; +} + + +# _private::Format::ModfISO: The bracketed, modified ISO 8601 date/time log file format handler +# ISO 8601 should be 2007-11-14T14:23:35+0800. But it is hard to read. +# This is a similar format commonly-seen in many applications. +package _private::Format::ModfISO; +use 5.008; +use strict; +use warnings; +use base qw(_private::Format); +use overload ("\"\"" => sub { "modified ISO 8601 date/time"; }); + +# match: Try matching my format and return the matching date text +sub match : method { + return $_[1] =~ /^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [+\-]\d{4})\]/? + $1: undef; +} + + +__END__ + +=head1 NAME + +arclog - Archive the log files monthly + +=head1 SYNOPSIS + + arclog [options] logfile... [output] + arclog [-h|-v] + +=head1 DESCRIPTION + +F archives the log files monthly. It strips off log entries +that belongs to previous months, and then compresses and saves them +to archived files named logfile.yyyymm.gz. + +Currently, F supports Apache access log, Syslog, NTP, Apache +1 SSL engine log and my own bracketed, modified ISO date/time log +file formats, and gzip and bzip2 compression methods. Several +software projects log (or can log) in a format compatible with the +Apache access log, like CUPS, ProFTPD, Pure-FTPd... etc., and +F can archive their Apache-like log files, too. + +Notice: I. To reduce the time occupying the +source log file, F copies the content of the source log +file to a temporary working file and restart the source log file +first. Then F can take its time working on the temporary +working file. However, please note: + +1. If you have a huge log file (several hundreds of MBs), merely +copying still takes a lot of time. In that case, you had better stop +logging first, archive the log file and restart logging, to avoid +racing condition in writing. If you archive the log file periodly, +it shall not grow too big. + +2. If F stops in the middle of the execution, it will leave +a temporary working file. The next time F runs, it will stop +when it sees that temporary working file. You have to process that +temporary working file first. That temporary working file is merely +a copy of the original log file. You can rename and archive it like +an ordinary log file to solve this. + +Do not sort unless you have a particular reason. Sorting has the +following potential problem: + +1. Sorting may I on large log files. The amount of +the memory required depends on the number of records in each archived +month. Modern Linux and MSWin32 have memory consuming protection by +killing processes that eats too much memory, but it still takes +minutes, and your system will hang during that time. I do not know +the memory consuming protection on other operating systems. If you +try, you are at your own risk. + +2. The time units of all recognized log formats are I. +Log records happen in a same second will be sorted by the log file +order (if you are archiving several log files at a time) and then +the log record order. I try to ensure that the sorted archived +records are in a correct order of the happening events, but I cannot +guarantee. You have to watch out if the order in a second is +important. + +Be careful on the L and NTP log files: +L and NTP does not record the year. F +uses L to parse the date, which assumes +the year between this month and last next month if the year is +missing. For ex., if today is 2001-06-08, it will then assume the +year between 2001-06-30 back to 2000-07-01 if the year is missing. I +think this is smart enough. However, if you do have a +L or NTP log file that has records older than one +year, do not use F. It will destroy your log file. + +If read from C, please note: + +1. You I specify the output prefix if you want to read from +C, since what it needs is an output pathname prefix, not an +output file. + +2. C cannot be deleted, restarted or partially kept. If you +read from C, the keep mode will fall back to keep all. if +you archive several source log files including C, the keep +mode will fall back to keep all for all source log files, to prevent +disaster. + +3. The answers of the C mode is obtained from C, too. +Since you have only one C, you cannot specify the C mode +while reading from C. It will fall back to the C mode +in that case. + +I suggest you to install L instead of +counting on the file executable. The internal magic file of +L seems to work better than the +L executable. F treats everything not +L nor L compressed as plain text. +When a compressed log file is wrongly recognized as an image, +F will treat it as plain text, read log records directly from +it and fail. This failure does not hurt the source log files, but is +still annoying. + +=head1 OPTIONS + +=over + +=item logfile + +The log file to be archived. Specify C<-> to read from C. +Multiple log files are supported. L or +L compressed files are supported, too. + +=item output + +The prefix of the output files. The output files will be named as +F, ie: F, F. If not +specified, the default is the same as the log file. You must specify +this if you want to read from C. You cannot specify C<-> +(C), since this is only a name prefix, not the output file. + +=item -c,--compress method + +Specify the compression method for the archived files. Log files +usually have large number of simular lines. Compress them saves +you lots of disk spaces. (And this is why we want to I +them.) Currently the following compression methods are supported: + +=over + +=item g,gzip + +Compress with L. This is the default. F +can use L to compress instead of +calling L. This can be safer and faster for not +calling foreign binaries. But if +L is not installed, it will try +to use L instead. If L is not +available, either, the program will fail. + +=item b,bzip2 + +Compress with L. F can use +L to compress instead of +calling L. This can be safer and faster for not +calling foreign binaries. But if +L is not installed, it will try +to use L instead. If L is not +available, either, the program will fail. + +=item n,none + +No compression at all. (Why? :p) + +=back + +=item --nocompress + +Do not compress the archived files. This is equal to +C<--compress none>. + +=item -s,--sort + +Sort the records by time (and then the record order). Sorting eats +huge memory and CPU, so it is disabled by default. See the +description above for a detailed illustration on sorting. + +=item --nosort + +Do not sort the records. This is the default. + +=item -o,--override mode + +Whether we should overwrite the existing archived files. Currently +the following modes are supported: + +=over + +=item o,overwrite + +Overwrite existing target files. You will lost these existing +records. Use with care. This is helpful if you are sure the master +log file has the most complete records. + +=item a,append + +Append the records to the existing target files. You may destroy the +log file completely by putting irrelevant entries altogether +accidently. Use with care. This is helpful if you append want to +merge 2 or more log files, for ex., 2 log files of different periods. + +=item i,ignore + +Ignore any existing target file, and discard all the records of those +months. You will lost these log records. Use with care. This is +helpful if you are supplying log records for the missing months, or +if you are merging the log records in a complex manner. + +=item f,fail + +Stop processing whenever a target file exists, to prevent destroying +existing files by accident. This should be mostly wanted when run +from some automatic mechanism, like L. So, +this is the default if no terminal is found at C. + +=item ask + +Ask you what to do when a target file exists. This should be most +wanted if you are running F interactively. So, this is the +default if a terminal is found at C. The answers are read +from C. Since you have only one C, you cannot specify +this mode if you want read the log file from C. In that case, +it will fall back to the fail mode. Also, if +F cannot get its answer from C, for ex., on a +closed C like L, it will fall back to +C mode. + +=back + +=item -k,--keep mode + +What to keep in the source file. Currently the following modes are +supported: + +=over + +=item a,all + +Keep the source file after records are archived. + +=item r,restart + +Restart the source file after records are archived. + +=item d,delete + +Delete the source file after records are archived. + +=item t,this-month + +Archive and strip records of previous months off from the log file. +Keep the records of this month in the source log file, to be archived +next month. This is designed to be run from L +monthly, so this is the default. + +=back + +=item -d, --debug + +Show the detailed debugging messages. + +=item -q, --quiet + +Shihhhhhh. Only yell when errors. + +=item -h, --help + +Display the help message and exit. + +=item -v, --version + +Output version information and exit. + +=back + +=head1 COPYRIGHT + +Copyright (c) 2001-2007 imacat. All rights reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but I; without even the implied warranty of +I or I. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see L. + +=head1 AUTHOR + +imacat . Please visit F's +websites at http://arclog.sourceforge.net/ and +http://www.imacat.idv.tw/tech/arclog.html . + +=head1 BUGS + +F has a mailing list at SourceForge: +arclog-users@lists.sourceforge.net. It is for +F's users to discuss and report problems. Its web page is +at http://lists.sourceforge.net/lists/listinfo/arclog-users . +If you have any problem or question on F, please go to +this page, join the list, and send your questions on this list. +Thank you. + +=head1 TODO + +=over + +=item Multi-lingual support + +Support multi-lingual, either with L or +perl 5.8.0's L. + +=back + +=head1 SEE ALSO + +L, L, +L, L, +L, L + +=cut diff --git a/arclog.en.html b/arclog.en.html new file mode 100644 index 0000000..093cdab --- /dev/null +++ b/arclog.en.html @@ -0,0 +1,506 @@ + + + + + + + + + + + + + + + +arclog Version 3.04 + + + +
+ 正體中文 | + 简体中文 | + English +
+
+ + +
+ + +

arclog Version 3.04

+ + +

What’s New?

+ +
+
2007-12-03
+ +
+

arclog version 3.04 is released. Documentation fixes. Upgrade is not necessary if you have installed arclog version 3.00 or later. Download arclog version 3.04.

+
+ + +
2007-12-03
+ +
+

arclog version 3.03 is released. Test suite fixes. Required Perl version number compatible to older versions, to work with the Perl 5.10 warning. Upgrade is not necessary if you have installed arclog version 3.00 or later. Download arclog version 3.03.

+
+ + +
2007-11-30
+ +
+

arclog version 3.02 is released. Test suite improvement, in order to deal with daylight saving time. Upgrade is not necessary if you have installed arclog version 3.00 or later. Download arclog version 3.02.

+
+ + +
2007-11-28
+ +
+

arclog version 3.01 is released. Test suite improvement, in order to catch CPAN tester failures. Upgrade is not necessary if you have installed arclog version 3.00. Download arclog version 3.01.

+
+ + +
2007-11-28
+ +
+

arclog version 3.00 is released. The code is completely new borrowed from reslog, with the name changed from arclog.pl to arclog, too. The new object-oriented handlers deal with different compression methods, formats nicely. Perl’s s build system ExtUtils::MakeMaker and Module::Build are used instead of GNU autoconf. And there is a complete test suite that help quality assurance. License updated to GPLv3. Download arclog version 3.00.

+
+ + +
2002-09-26
+ +
+

arclog.pl version 2.1.0 is released. This is the final 2.1.0 release. It adds support for bzip2 compression, gzip compression with gzip binary instead of Compress::Zlib, and GNU autoconf configuration script. Download arclog.pl version 2.1.0.

+
+ + +
2002-09-18
+ +
+

arclog.pl version 2.1.0dev2 is released. This release corrects several documentation errors. It also adds SourceForge in the documentations as one of the sources of arclog.pl. You can think of it as a Source Forge Memorial Release. :p You do nott have to upgrade to this version in a rush. Download arclog.pl version 2.1.0dev2.

+
+ + +
2002-09-17
+ +
+

arclog.pl is hosted at SourceForge now! Congratulations! (Although I’m still trying hard to get it working at this time… ^^; )

+
+
+ + +

Description

+ +

arclog archives the log files monthly. It strips off previous months’ log records from the log file, and save them to compressed archive files named logfile.yyyymm. It then saves the hard disk space and prevents potential attacks on log files.

+ +

Currently, arclog supports Apache access log, Syslog, NTP, Apache 1 SSL engine log and my own bracketed, modified ISO date/time log file formats, and gzip and bzip2 compression methods. Several software projects log (or can log) in a format compatible with the Apache access log, like CUPS, ProFTPD, Pure-FTPdetc., and arclog can archive their Apache-like log files, too.

+ + +

Caution

+ +
    +
  • Archiving takes time. To reduce the time occupying the source log file, arclog copies the content of the source log file to a temporary working file and restart the source log file first. Then arclog can take its time working on the temporary working file. However, please note:

    +
      +
    1. If you have a huge log file (several hundreds of MBs), merely copying still takes a lot of time. You had better stop logging first, archive the log file and restart logging, to avoid racing condition in writing. If you archive the log file periodly, it shall not grow too big.

    2. +
    3. Ifarclog stops in the middle of the execution, it will leave a temporary working file. The next time arclog runs, it will stop when it sees that temporary working file. You have to process that temporary working file first. That temporary working file is merely a copy of the original log file. You can rename and archive it like an ordinary log file to solve this.

    4. +
    +
  • + +
  • Do not sort unless you have a particular reason. Sorting has the following potential problem:

    +
      +
    1. Sorting may eat huge memory on large log files. The amount of the memory required depends on the number of records in each archived month. Modern Linux and MS-Windows have memory consuming protection by killing processes that eats too much memory, but it still takes minutes, and your system will hang during that time. I do not know the memory consuming protection on other operating systems. If you try, you are at your own risk.

    2. +
    3. The time units of all recognized log formats are second. Log records happen in a same second will be sorted by the log file order (if you are archiving several log files at a time) and then the log record order. I try to ensure that the sorted archived records are in a correct order of the happening events, but I cannot guarantee. You have to watch out if the order in a second is important.

    4. +
    +
  • + +
  • Be careful on the Syslog and NTP log files: Syslog and NTP does not record the year. arclog uses Date::Parse to parse the date, which assums the year between this month and last next month if the year is missing. For ex., if today is 2001-06-08, it will then assume the year between 2001-06-30 back to 2000-07-01. I think this is smart enough. However, if you do have a Syslog or NTP log file that has records older than one year, do not use arclog. It will destroy your log file.

  • + +
  • If read from STDIN, please note:

    +
      +
    1. You must specify the output prefix if you want to read from STDIN, since what it needs is an output pathname prefix, not an output file.

    2. +
    3. STDIN cannot be deleted, restarted or partially kept. If you read from STDIN, the keep mode will fall back to keep all. If you archive several source log files including STDIN, the keep mode will fall back to keep all for all source log files, to prevent disaster.

    4. +
    5. The answers of the ask mode is obtained from STDIN, too. Since you have only one STDIN, you cannot specify the ask mode while reading from STDIN. It will fall back to the fail mode in that case.

    6. +
    +
  • + +
  • I suggest you to install File::MMagic instead of counting on the file executable. The internal magic file of File::MMagic seems to work better than the file executable. arclog treats everything not gzip nor bzip2 compressed as plain text. When a compressed log file is wrongly recognized as an image, arclog will treat it as plain text, read log records directly from it and fail. This failure does not hurt the source log files, but is still annoying.

  • +
+ + +

System Requirement

+ +
    +
  1. Perl, version 5.8.0 or above. arclog uses 3-argument open() to duplicate filehandles, which is only supported since 5.8.0. I have not successfully port this onto earlier versions yet. Please tell me if you made it. You can run perl -v to see your current Perl version. If you do not have Perl, or if you have an older version of Perl, you can download and install/upgrade it from Perl website. If you are using MS-Windows, you can download and install ActiveState ActivePerl.

  2. + +
  3. Required Perl modules:

    + +
    +
    Date::Parse
    + +
    +

    This is used to parse the timestamp of the log records. You can download and install Date::Parse from the CPAN archive, or install it with the CPAN shell by running cpan Date::Parse, or install it with the CPANPLUS shell by running cpanp i Date::Parse. Debian/Ubandu Linux users can install it by running apt-get install libtimedate-perl. Red Hat/Fedora/CentOS Linux users can install it by running yum install perl-TimeDate. FreeBSD users can install it by running ports install p5-TimeDate. ActivePerl users can install it by running ppm install Date::Parse.

    +
    +
    + +

    If you install arclog with the CPAN or CPAN shell, the above shall be automatically installed.

    +
  4. + +
  5. Optional Perl modules:

    + +
    +
    File::MMagic
    + +
    +

    This is used to check the file type. If this is not available, arclog will look for the file executable instead. If that is not available, too, arclog will judge the file type by its name suffix (extension). In that case arclog will fail when reading from STDIN. You can download and install File::MMagic from the CPAN archive, or install it with the CPAN shell by running cpan File::MMagic, or install it with the CPANPLUS shell by running cpanp i Term::ReadKey. Debian/Ubandu Linux users can install it by running apt-get install libfile-mmagic-perl. Red Hat/Fedora/CentOS Linux users can install it by running yum install perl-File-MMagic. FreeBSD users can install it by running ports install p5-File-MMagic. ActivePerl users can install it by running ppm install File::MMagic. The alternative file.exe for MS-Windows can be obtained from the GnuWin32 home page. Be sure to save it as file.exe somewhere in your PATH.

    + +

    It is preferred to use File::MMagic. The file executable seems to make mistakes occationally.

    +
    + +
    Compress::Zlib
    + +
    +

    This is used to support read/write of gzip compressed files. It is only needed when gzip compressed files are encountered. If it is not available when needed, arclog will try to use the gzip executable instead. If that is not available, too, arclog will fail. You can download and install Compress::Zlib from the CPAN archive, or install it with the CPAN shell by running cpan Compress::Zlib, or install it with the CPANPLUS shell by running cpanp i Compress::Zlib. Debian/Ubandu Linux users can install it by running apt-get install libcompress-zlib-perl. Red Hat/Fedora/CentOS Linux users can install it by running yum install perl-Compress-Zlib. FreeBSD users can install it by running ports install p5-Compress-Zlib. ActivePerl users can install it by running ppm install Compress::Zlib. The alternative gzip.exe for MS-Windows can be obtained from the gzip home page. Be sure to save it as gzip.exe somewhere in your PATH.

    +
    + +
    Compress::Bzip2, version 2 or above
    + +
    +

    This is used to support read/write of bzip2 compressed files. It is only needed when bzip2 compressed files are encountered. If it is not available when needed, arclog will try to use the bzip2 executable instead. If that is not available, too, arclog will fail. Notice that older versions before 2 does not work, since file I/O compression were not implemented yet. You can download and install Compress::Bzip2 from the CPAN archive, or install it with the CPAN shell by running cpan Compress::Bzip2, or install it with the CPANPLUS shell by running cpanp i Compress::Bzip2. Debian/Ubandu Linux users can install it by running apt-get install libcompress-bzip2-perl. Red Hat/Fedora/CentOS Linux users can install it by running yum install perl-Compress-Bzip2. FreeBSD users can install it by running ports install p5-Compress-Bzip2. ActivePerl users can install it by running ppm install Compress::Bzip2. The alternative bzip2.exe for MS-Windows can be obtained from the bzip2 home page. Be sure to save it as bzip2.exe somewhere in your PATH.

    +
    + +
    Term::ReadKey
    + +
    +

    This is used to display the progress bar. Without this arclog will not display the progress bar, but nothing else is different. The progress bar is a good visual representation of what arclog is currently doing. You can download and install Term::ReadKey from the CPAN archive, or install it with the CPAN shell by running cpan Term::ReadKey, or install it with the CPANPLUS shell by running cpanp i Term::ReadKey. Debian/Ubandu Linux users can install it by running apt-get install libterm-readkey-perl. Red Hat/Fedora/CentOS Linux users can install it by running yum install perl-TermReadKey. FreeBSD users can install it by running ports install p5-Term-ReadKey. ActivePerl users can install it by running ppm install Term::ReadKey.

    +
    +
    +
  6. +
+ + +

Download

+ +

arclog’s official websites is at…

+ + + +

You can always download the newest version of arclog from…

+ + + +

imacat’s PGP public key is at…

+ + + + +

Install

+ +

If you are upgrading from arclog.pl 2.1.1dev4 or earlier, please read UPGRADE for some upgrade instruction.

+ +

Install with ExtUtils::MakeMaker

+ +

arclog uses standard Perl installation with ExtUtils::MakeMaker. Follow these steps:

+ +
+% perl Makefile.PL
+% make
+% make test
+% make install
+
+ +

When running make install, make sure you have the priviledge to write to the installation location. This usually requires the root priviledge.

+ +

If you are using ActivePerl under MS-Windows, you should use nmake instead of make. nmake can be obtained from the Microsoft FTP site.

+ +

If you want to install into another location, you can set the PREFIX. For example, to install into your home when you are not root:

+ +
+% perl Makefile.PL PREFIX=/home/jessica
+
+ +

Refer to the docuemntation of ExtUtils::MakeMaker for more installation options (by running perldoc ExtUtils::MakeMaker).

+ + +

Install with Module::Build

+ +

You can install with Module::Build instead, if you prefer. Follow these steps:

+ +
+% perl Build.PL
+% ./Build
+% ./Build test
+% ./Build install
+
+ +

When running ./Build install, make sure you have the priviledge to write to the installation location. This usually requires the root priviledge.

+ +

If you want to install into another location, you can set the --prefix. For example, to install into your home when you are not root:

+ +
+% perl Build.PL --prefix=/home/jessica
+
+ +

Refer to the docuemntation of Module::Build for more installation options (by running perldoc Module::Build).

+ + +

Options

+ +
+./arclog [options] logfile… [output]
+./arclog [-h|-v]
+
+ + +
+
logfile
+ +
+

The log file to be archived. Specify - to read from STDIN. Multiple log files are supported. gzip or bzip2 compressed files are supported, too.

+
+ + +
output
+ +
+

The prefix of the output files. The output files will be named as output.yyyymm, i.e., output.200101, output.200102. If not specified, the default is the same as the log file. You must specify this if you want to read from STDIN. You cannot specify - (STDIN), since this is only a name prefix, not the output file.

+
+ + +
-c, --compress method
+ +
+

Specify the compression method for the archived files. Log files usually have large number of simular lines. Compress them saves you lots of disk spaces. (And this is why we want to archive them.) Currently the following compression methods are supported:

+ + +
+
g, gzip
+ +
+

Compress with gzip. This is the default. arclog can use Compress::Zlib to compress instead of calling gzip. This can be safer and faster for not calling foreign binaries. But if Compress::Zlib is not installed, it will try to use gzip binary instead. If gzip binary is not available, either, but gzip compression is required, the program will fail.

+
+ + +
b, bzip2
+ +
+

Compress with bzip2. arclog can use Compress::Bzip2 to compress instead of calling bzip2. This can be safer and faster for not calling foreign binaries. But if Compress::Bzip2 is not installed, it will try to use bzip2 binary instead. If bzip2 binary is not available, either, but bzip2 compression is required, the program will fail.

+
+ + +
n, none
+ +
+

No compression at all. (Why? :p)

+
+
+
+ + +
--nocompress
+ +
+

Do not compress the archived files. This is equal to --compress none.

+
+ + +
-s, --sort
+ +
+

Sort the records by time (and then the record order). Sorting eats huge memory and CPU, so it is disabled by default. See the description above for a detailed illustration on sorting.

+
+ + +
--nosort
+ +
+

Do not sort the records. This is the default.

+
+ + +
-o, --override mode
+ +
+

Whether we should overwrite the existing archived files. Currently the following modes are supported:

+ + +
+
o, overwrite
+ +
+

Overwrite existing target files. You will lost these existing records. Use with care. This is helpful if you are sure the master log file has the most complete records.

+
+ + +
a, append
+ +
+

Append the records to the existing target files. You may destroy the log file completely by putting irrelevant entries altogether accidently. Use with care. This is helpful if you append want to merge 2 or more log files, for ex., 2 log files of different periods.

+
+ + +
i, ignore
+ +
+

Ignore any existing target file, and discard all the records of those months. You will lost these log records. Use with care. This is helpful if you are supplying log records for the missing months, or if you are merging the log records in a complex manner.

+
+ + +
f, fail
+ +
+

Stop processing whenever a target file exists, to prevent destroying existing files by accident. This should be mostly wanted when run from some automatic mechanism, like crontab. So, this is the default if no terminal is found at STDIN.

+
+ + +
ask
+ +
+

Ask you what to do when a target file exists. This should be most wanted if you are running arclog interactively. So, this is the default if a terminal is found at STDIN. The answers are read from STDIN. Since you have only one STDIN, you cannot specify this mode if you want read the log file from STDIN. In that case, it will fall back to the fail mode. Also, if arclog cannot get its answer from STDIN, for ex., on a closed STDIN like crontab, it will fall back to fail mode.

+
+
+
+ + +
-k, --keep mode
+ +
+

What to keep in the source file. Current the following modes are supported:

+ +
+
a, all
+ +
+

Keep the source file after records are archived.

+
+ + +
r, restart
+ +
+

Restart the source log file after records are archived.

+
+ + +
d, delete
+ +
+

Delete the source log file after records are archived.

+
+ + +
t, this-month
+ +
+

Archive and strip records of previous months off from the log file. Keep the records of this month in the source log file, to be archived next month. This is designed to be run from crontab monthly, so this is the default.

+
+
+
+ + +
-d, --debug
+ +
+

Show the detailed debugging messages.

+
+ + +
-q, --quiet
+ +
+

Shihhhhhh. Only yell when errors.

+
+ + +
-h, --help
+ +
+

Display the help message and exit.

+
+ + +
-v, --version
+ +
+

Output version information and exit.

+
+
+ + +

Copyright

+ +

Copyright © 2001-2007 imacat..

+ +

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

+ +

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

+ +

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

+ + +

Release Notes

+ +

Please read the NEWS for the new functions and bug fixes.

+ + +

Support

+ +

arclog is hosted on SourceForge, CPAN and Tavern IMACAT’s. For the latest infomation, see

+ + + +

There is a arclog mailing list hosted at SourceForge. Please submit your questions, suggestions or bug reports there. It is a Mailman mailing list. For more information, see the arclog mailing list page. Alternatively, you can send a mail to the e-mail command mailbox with the subject help for a list of available e-mail commands.

+ +
+ + +
+ + + + diff --git a/arclog.zh-cn.html b/arclog.zh-cn.html new file mode 100644 index 0000000..7c130e9 --- /dev/null +++ b/arclog.zh-cn.html @@ -0,0 +1,510 @@ + + + + + + + + + + + + + + + +arclog 3.04 °æ + + + +
+ Õý體ÖÐÎÄ | + ¼òÌåÖÐÎÄ | + English +
+
+ + +
+ + +

arclog 3.04 °æ

+ + +

×îÐÂÏûÏ¢

+ +
+
2007-12-03
+ +
+

arclog ×îа汾 3.04 ¡£ËµÃ÷ÎļþÐÞÕý¡£ÈôÄã֮ǰ°²×°ÁË arclog 3.00 °æ»òÖ®ºóµÄ°æ±¾£¬²»ÐèÒªÉý¼¶Ð°档ÏÂÔØ arclog 3.04 °æ¡£

+
+ + +
2007-12-03
+ +
+

arclog ×îа汾 3.03 ¡£ÐÞÕý²âÊÔÌ×¼þ¡£ËùÐè Perl °æ±¾ºÅÂë¸ÄÓÃÏàÈÝ춾ɰæµÄºÅÂë¸ñʽ£¬ÒÔÏû³ý Perl 5.10 µÄ¾¯¸æѶϢ¡£ÈôÄã֮ǰ°²×°ÁË arclog 3.00 °æ»òÖ®ºóµÄ°æ±¾£¬²»ÐèÒªÉý¼¶Ð°档ÏÂÔØ arclog 3.03 °æ¡£

+
+ + +
2007-11-30
+ +
+

arclog ×îа汾 3.02 ¡£ÐÞÕý²âÊÔÌ×¼þ£¬ÒÔ´¦ÀíÈÕ¹â½ÚԼʱ¼äÎÊÌâ¡£ÈôÄã֮ǰ°²×°ÁË arclog 3.00 °æ»òÖ®ºóµÄ°æ±¾£¬²»ÐèÒªÉý¼¶Ð°档ÏÂÔØ arclog 3.02 °æ¡£

+
+ + +
2007-11-28
+ +
+

arclog ×îа汾 3.01 ¡£ÐÞÕý²âÊÔÌ×¼þ£¬ÒÔЭÖúÀåÇå CPAN ²âÊԻر¨µÄ´íÎó¡£ÈôÄã֮ǰ°²×°ÁË arclog 3.00 °æ£¬²»ÐèÒªÉý¼¶Ð°档ÏÂÔØ arclog 3.01 °æ¡£

+
+ + +
2007-11-28
+ +
+

arclog ×îа汾 3.00 ¡£´Ó reslog ½è¹ýÀ´µÄȫгÌʽÂ룬µµÃûÒ²´Ó arclog.pl ¸ÄΪ arclog ¡£ÐµÄÎï¼þµ¼Ïò´¦ÀíÆ÷£¬¿É˳Àû´¦Àí¸÷ÖÖѹËõ·¨¼°µµ°¸¸ñʽ¡£°²×°ÏµÍ³ÓÉ GNU autoconf ¸ÄÓà Perl µÄ ExtUtils::MakeMaker ºÍ Module::Build ¡£Ð¼ÓÉÏÍêÕûµÄ²âÊÔÌ×¼þ£¬Ð­Öú³ÌʽƷ¹Ü¡£°æȨ¸üÐÂΪ GPLv3 ¡£ÏÂÔØ arclog 3.00 °æ¡£

+
+ + +
2002-09-26
+ +
+

arclog.pl ×îа汾 2.1.0 ¡£ÕâÊÇ 2.1.0 µÄ×îÖհ棬¼ÓÉÏÁË bzip2 ѹËõµÄÖ§Ô®£¬Óà gzip ³Ìʽ´úÌæ Compress::Zlib ѹËõ£¬²¢¸ÄÓà GNU autoconf °²×°É趨³Ìʽ¡£ÏÂÔØ arclog.pl 2.1.0 ¡£

+
+ + +
2002-09-18
+ +
+

arclog.pl ×îа汾 2.1.0dev2 ¡£±¾°æÐÞÕýÁ˼¸¸ö˵Ã÷ÎļþµÄ´íÎ󣬲¢°Ñ SourceForge ¼Ó½ø arclog.pl µÄÏÂÔØÍøÖ·ÖС£Äã¿ÉÒÔ°ÑËüµ±×öÉêÇë SourceForge ¼ÍÄî°æ¡£Ô­ÔòÉÏ£¬²»ÐèÒª¼±ÖøÉý¼¶¡£ÏÂÔØ arclog.pl 2.1.0dev2 ¡£

+
+ + +
2002-09-17
+ +
+

ºÃÏûÏ¢£¡ arclog.pl ÒÑ¿ªÊ¼¼ÜÉèì¶ SourceForge ÂÞ£¡£¨ËäÈ»ÎÒ¼¸ºõ»¹ÍêÈ«¸ã²»Çå³þÒªÔõô¼Ü¡­ÃþË÷ÖС­ ^^; £©

+
+
+ + + +

˵Ã÷

+ +

arclog ÊǼǼµµÃ¿Ô¹鵵³Ìʽ£¬½«¼Ç¼µµÖУ¬Ç°ÔµļǼ°´Ô·ÝѹËõ¹éµµ£¬ÒÔ½ÚÊ¡Ó²µú¿Õ¼ä£¬²¢±ÜÃâ¼Ç¼µµ±»ÓÐÐÄÈËÊ¿ÆÆ»µ¡£

+ +

arclog Ä¿Ç°Ö§Ô® Apache ¡¢ Syslog ¡¢ NTP ¡¢ Apache 1 SSL engine log ¼°ÎÒ×Ô¼ºÓõÄÀ¨»¡ ISO ÐÞÕý¸ñʽÎåÖÖ¸ñʽµÄ¼Ç¼µµ£¬Óë gzip ºÍ bzip2 Á½ÖÖѹËõ·¨¡£ºÜ¶à³Ìʽ¶¼¿ÉÒÔÓà Apache ÏàÈݼǼµµ¸ñʽ¼Ç¼£¬Èç CUPS ¡¢ ProFTPD ¡¢ Pure-FTPd…µÈ£¬ arclog Ò²¿ÉÒԹ鵵ÕâЩ Apache ÏàÈݸñʽµÄ¼Ç¼µµ¡£

+ + +

×¢ÒâÊÂÏî

+ +
    +
  • ¹éÀà¼Ç¼µµºÜºÄʱ¼ä¡£Îª¼õÉÙÕ¼ÓÃÔ­¼Ç¼µµµÄʱ¼ä£¬ arclog »áÏÈ°ÑÔ­¼Ç¼µµ¸´ÖƵ½ÔÝʱ¹¤×÷µµ£¬ÊÓÐèÒª°ÑÔ­¼Ç¼µµ¹éÁ㣬ÔÙÂýÂýÔÚÔÝʱ¹¤×÷µµÉÏ×÷Òµ¡£²»¹ýÈÔÇë×¢ÒâÏÂÁÐÊÂÏ

    +
      +
    1. Èç¹ûÔ­¼Ç¼µµºÜ´ó£¨ºÃ¼¸°Ù MB £©£¬¹â¸´ÖƵµ°¸¾ÍºÜ»¨Ê±¼äÁË¡£ÕâÖÖÇé¿öÏ£¬×îºÃÏȹرռǼ³Ìʽ£¬µÈÕûÀíÍêÒÔºó£¬ÔÙ¼ÌÐø¼Ç¼£¬ÒÔ±ÜÃâ¼Ç¼´íÂÒ¡£Èôƽ³£Óж¨Æڹ鵵£¬¼Ç¼µµ¾Í²»»áÎÞÏÞÖÆÅòÕÍÁË¡£

    2. +
    3. Èô arclog Ö´Ðе½Ò»°ëÒò¹ÊÖжϣ¬»áÁôϲдæµÄÔÝʱ¹¤×÷µµ¡£ÈÕºó arclog Ö´ÐÐʱ£¬Åöµ½Ö®Ç°²Ð´æµÄÔÝʱ¹¤×÷µµ£¬»áÍ£Ö¹Ö´ÐС£ÒªÏÈ´¦Àíµô֮ǰµÄÔÝʱ¹¤×÷µµ£¬²ÅÄܼÌÐø¡£ÔÝʱ¹¤×÷µµÖ»ÊÇÔ­µµµÄ¸´±¾£¬Ö»Òª¸Ä¸öµµÃûÔٹ鵵һ´Î£¬¾Í¿ÉÒÔÁË¡£

    4. +
    +
  • + +
  • ûÓÐÌرðÀíÓÉ£¬×îºÃ²»ÒªÅÅÐò¡£ÅÅÐòµÄDZÔÚÎÊÌâÈçÏ£º

    +
      +
    1. ¼Ç¼µµºÜ´óʱ£¬ÅÅÐò»á³ÔµôºÜ¶à¼ÇÒäÌå¡£ËùÐè¼ÇÒäÌåÒÀ¹éµµºóÿ¸öԼǼ±ÊÊý¶ø¶¨¡£Ð°æµÄ Linux ºÍ MS-Windows ϵͳÓмÇÒäÌåºÄÓñ£»¤£¬»áÖжϳԵôÌ«¶à¼ÇÒäÌåµÄ³Ìʽ£¬²»¹ýÕ⻹ÊÇÒª»¨ºÃ¼¸·ÖÖÓ£¬Õ⼸·ÖÖÓÄÚϵͳ»áÍêÈ«µ±µô²»¶¯¡£ÎÒ²»ÖªµÀ±ðµÄ×÷ҵϵͳÓÐûÓмÇÒäÌåºÄÓñ£»¤¡£Èç¹ûÄãÒªÍ棬·çÏÕ×Ô¸º¡£

    2. +
    3. ËùÓÐÖ§Ô®µÄ¼Ç¼µµ¸ñʽ£¬Ê±¼ä×îСµ¥Î»ÎªÃ롣ͬһÃëÄڵļǼ»áÏÈÒԼǼµµË³Ðò£¨Èôͬʱ¹éµµºÃ¼¸¸ö¼Ç¼µµ£©£¬ÔÙÒԼǼ±¾Éí³öÏֵĴÎÐòÅÅÐò¡£ÕâÑùÉè¼Æ¾¡¿ÉÄÜÈÃÅÅÐò¹éµµºóͬһÃëÄڵļǼ´ÎÐò£¬ºÍʼþÕæÕýµÄ·¢Éú˳ÐòÒ»Ö£¬µ«Ò²ÎÞ·¨ÍêÈ«±£Ö¤¡£ÈôͬһÃëÄÚµÄʼþ´ÎÐòºÜÖØÒª£¬ÄãÒª×ÔÐÐСÐÄ¡£

    4. +
    +
  • + +
  • ¹éµµ Syslog ºÍ NTP ¼Ç¼µµÊ±£¬ÇëÌرð×¢Ò⣺ Syslog ºÍ NTP ¼Ç¼µµÃ»ÓмÇÄê¡£ arclog Óà Date::Parse Ä£×é½â¶Áʱ¼ä¡£ÎÞÄê·Ýʱ£¬ Date::Parse »á°ÑÄê·ÝÉèÔÚÕâ¸öÔµ½È¥ÄêµÄϸöÔÂÖ®¼ä¡£ÀýÈ磬Èô½ñÌìÊÇ 2001-06-08 £¬ÄÇÄê·Ý»áÉèÔÚ 2001-06-30 µ½ 2000-07-01 Ö®¼ä¡£ÎÒÔ­ÔòÉÏÔÞ³ÉÕâÑù¡£²»¹ý£¬ÈôÄãµÄ Syslog »ò NTP ¼Ç¼µµ³¬¹ýÒ»ÄêÕûÀí¹éµµ£¬²»ÒªÅÜ arclog £¬·ñÔò¼Ç¼µµ»á´óÂÒ¡£

  • + +
  • ´Ó±ê×¼ÊäÈë¶Á¼Ç¼µµ£¬Çë×¢ÒâÏÂÁÐÊÂÏ

    +
      +
    1. ÈôÒª¶Á±ê×¼ÊäÈ룬¾ÍÒ»¶¨ÒªÉ趨¹éµµÊ±£¬µµÃûµÄ¿ªÍ·£¬²»È»²»ÖªµÀÔõô¹éµµºóÒª´æµ½ÄÄÀïÈ¥¡£

    2. +
    3. ±ê×¼ÊäÈëÎÞ·¨É¾³ý¡¢¹éÁã»ò±£Áô²¿·ÝÄÚÈÝ¡£ÈôÒª¶Á±ê×¼ÊäÈ룬ԭµµ±£Áôģʽ»á×Ô¶¯Í˻سÉÈ«²¿±£Áô¡£Ò»´Î¶ÁÈë¶àµµÊ±£¬ÈôÆäÖÐÓбê×¼ÊäÈ룬»áÒ»ÂÉÍË»ØÈ«²¿±£Áô£¬ÒÔ±ÜÃâ»ìÂÒ¡£

    4. +
    5. ask ģʽµÄ»Ø´ðÒ²ÊÇ´Ó±ê×¼ÊäÈë¶ÁµÄ¡£ÒòΪ±ê×¼ÊäÈëÖ»ÓÐÒ»¸ö£¬ËùÒÔ´Ó±ê×¼ÊäÈë¶ÁµµÊ±£¬ÎÞ·¨ÅÜ ask ģʽ£¬»á×Ô¶¯Í˻ص½ fail ģʽ¡£

    6. +
    +
  • + +
  • ÎÒ½¨Òé°²×° File::MMagic £¬¾¡Á¿²»ÒªÓà file ³Ìʽ¡£ File::MMagic ÄÚ½¨µÄµµ°¸ÀàÐͱíºÃÏñ±È file ³Ìʽ׼ȷ¡£Èô²»ÊÇ gzip »ò bzip2 ѹËõµµ£¬ arclog »á°ÑÊÓΪµ±³É´¿ÎÄ×Öµµ¡£ÈôѹËõµµ±»ÎóÅÐΪͼµµ£¬ arclog »áµ±³É´¿ÎÄ×Öµµ£¬Ö±½Ó¶Á¼Ç¼£¬²¢ÒÔ´íÎó½áÊø¡£¾ÍËã´íÎóÒ²²»»áŪÂÒÔ­¼Ç¼µµ£¬²»¹ý¶àÉÙÓеãÂé·³¡£

  • +
+ + +

ϵͳÐèÇó

+ +
    +
  1. Perl 5.8.0 ÒÔÉÏ¡£ arclog ÓÃÈý¸ö²ÎÊýµÄ open() À´¸´ÖƵµ°¸²Ù×÷£¬ÎÒ»¹²»ÖªµÀÔõô¸Äдµ½¸üÔçµÄ°æ±¾ÉÏÖ´ÐС£ÈôÄã¿ÉÒÔ¸Äдµ½¸üÔçµÄ°æ±¾ÉÏÖ´ÐУ¬Çë¸æËßÎÒ¡£Äã¿ÉÒÔÊäÈë perl -v ²éѯÄãÄ¿Ç°µÄ Perl °æ±¾¡£Èç¹ûÄãûÓÐ Perl »òÐèÒªÉý¼¶£¬¿ÉÒÔµ½ Perl ÍøÕ¾ÏÂÔØ°²×°×îаæ Perl ¡£ÈôÄãÊÇÓà MS-Windows £¬¿ÉÒÔµ½ ActiveState ¹«Ë¾ÏÂÔØ ActivePerl °²×°¡£

  2. + +
  3. Ðè´îÅäµÄ Perl Ä£×飺

    + +
    +
    Date::Parse
    + +
    +

    ÕâÊDZæʶ¼Ç¼ʱ¼äÓõġ£Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Date::Parse £¬»òÓà CPAN Shell Ö´ÐÐ cpan Date::Parse °²×°£¬»òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Date::Parse °²×°¡£ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ apt-get install libtimedate-perl °²×°¡£ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ yum install perl-TimeDate °²×°¡£ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ports install p5-TimeDate °²×°¡£ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ppm install Date::Parse °²×°¡£

    +
    +
    +
  4. + +
  5. Ñ¡ÅäµÄ Perl Ä£×飺

    + +
    +
    File::MMagic
    + +
    +

    ÕâÊǼì²éµµ°¸ÀàÐÍÓõġ£ÈôûÓа²×°£¬ arclog »áÕÒ file ³Ìʽ´úÌæ¡£Èô»¹ÕÒ²»µ½£¬ arclog »á¸ÄÓõµÎ²£¨¸±µµÃû£©Åжϵµ°¸ÀàÐÍ¡£ÕâʱÈô´Ó±ê×¼ÊäÈë¶Áµµ£¬ arclog ¾ÍÎÞ·¨ÅжÏÁË¡£Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° File::MMagic £¬»òÓà CPAN Shell Ö´ÐÐ cpan File::MMagic °²×°£¬»òÓà CPANPLUS Shell Ö´ÐÐ cpanp i File::MMagic °²×°¡£ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ apt-get install libfile-mmagic-perl °²×°¡£ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ yum install perl-File-MMagic °²×°¡£ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ports install p5-File-MMagic °²×°¡£ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ppm install File::MMagic °²×°¡£ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà file.exe ³Ìʽ£¬¿ÉÒÔÓÉ GnuWin32 ÍøÕ¾ÏÂÔØ¡£ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ file.exe ¡£

    + +

    ½¨ÒéÓà File::MMagic ¡£ file ³Ìʽż¶û»áÎóÅС£

    +
    + +
    Compress::Zlib
    + +
    +

    ÕâÊÇ´¦Àí gzip ѹËõµµÓõģ¬Ö»ÓÐÔÚ´¦Àí gzip ѹËõµµ²Å»áÓõ½¡£ÈôÒªÓÃʱûÓа²×°£¬ arclog »áÊÔÖø¸ÄÓà gzip ³Ìʽ´úÌæ¡£Èô»¹ÕÒ²»µ½£¬ arclog ¾ÍÎÞ·¨Ö´ÐС£Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Compress::Zlib £¬»òÓà CPAN Shell Ö´ÐÐ cpan Compress::Zlib °²×°£¬»òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Compress::Zlib °²×°¡£ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ apt-get install libcompress-zlib-perl °²×°¡£ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ yum install perl-Compress-Zlib °²×°¡£ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ports install p5-Compress-Zlib °²×°¡£ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ppm install Compress::Zlib °²×°¡£ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà gzip.exe ³Ìʽ£¬¿ÉÒÔÓÉ gzip ÍøÕ¾ÏÂÔØ¡£ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ gzip.exe ¡£

    +
    + +
    Compress::Bzip2 µÚ¶þ°æÒÔÉÏ
    + +
    +

    ÕâÊÇ´¦Àí bzip2 ѹËõµµÓõģ¬Ö»ÓÐÔÚ´¦Àí bzip2 ѹËõµµ²Å»áÓõ½¡£ÈôÒªÓÃʱûÓа²×°£¬ arclog »áÊÔÖø¸ÄÓà bzip2 ³Ìʽ´úÌæ¡£Èô»¹ÕÒ²»µ½£¬ arclog ¾ÍÎÞ·¨Ö´ÐС£Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Compress::Bzip2 £¬»òÓà CPAN Shell Ö´ÐÐ cpan Compress::Bzip2 °²×°£¬»òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Compress::Bzip2 °²×°¡£ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ apt-get install libcompress-bzip2-perl °²×°¡£ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ yum install perl-Compress-Bzip2 °²×°¡£ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ports install p5-Compress-Bzip2 °²×°¡£ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ppm install Compress::Bzip2 °²×°¡£ÈôÄãÒªÔÚ MS-Windows ÏÂʹÓà bzip2.exe ³Ìʽ£¬¿ÉÒÔÓÉ bzip2 ÍøÕ¾ÏÂÔØ¡£ÇëÈ·ÈÏÏÂÔغ󣬴浵ÔÚϵͳµÄ·¾¶Ï£¬µµÃûΪ bzip2.exe ¡£

    +
    + +
    Term::ReadKey
    + +
    +

    ÕâÊÇÏÔʾ½ø¶ÈÁÐÓõģ¬ÈôûÓа²×°£¬¾Í²»»áÏÔʾ½ø¶ÈÁС£´ËÍâ²»»áÓÐÈκÎÎÊÌâ¡£½ø¶ÈÁпÉÒÔÈÃÄã¶Ô arclog µÄ¹¤×÷½ø¶ÈһĿÁËÈ»¡£Äã¿ÉÒÔÓÉ CPAN Ä£×é¿âÏÂÔØ°²×° Term::ReadKey £¬»òÓà CPAN Shell Ö´ÐÐ cpan Term::ReadKey °²×°£¬»òÓà CPANPLUS Shell Ö´ÐÐ cpanp i Term::ReadKey °²×°¡£ÈôÄãÊÇ Debian/Ubandu Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ apt-get install libterm-readkey-perl °²×°¡£ÈôÄãÊÇ Red Hat/Fedora/CentOS Linux ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ yum install perl-TermReadKey °²×°¡£ÈôÄãÊÇ FreeBSD ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ports install p5-Term-ReadKey °²×°¡£ÈôÄãÊÇ ActivePerl ʹÓÃÕߣ¬¿ÉÒÔÖ´ÐÐ ppm install Term::ReadKey °²×°¡£

    +
    +
    +
  6. +
+ + +

ÏÂÔØ

+ +

arclog µÄ¹Ù·½ÍøÕ¾ÔÚ£º

+ + + +

×îаæ arclog ¿ÉÓÉÏÂÁÐλַÏÂÔØ£º

+ + + +

ÒÀÂêèµÄ PGP ¹«Ô¿ÔÚ£º

+ + + + +

°²×°

+ +

ÈôÄãÊÇÓÉ arclog.pl 2.1.1dev4 ÒÔÇ°µÄ°æ±¾Éý¼¶£¬Çë²ÎÔÄ UPGRADE.zh-cn µµµÄÉý¼¶ËµÃ÷¡£

+ +

ÒÔ ExtUtils::MakeMaker °²×°

+ +

arclog Óà Perl ±ê×¼µÄ ExtUtils::MakeMaker °²×°£¬³ÌÐòÈçÏ£º

+ +
+% perl Makefile.PL
+% make
+% make test
+% make install
+
+ +

ÔÚ make install Ç°£¬ÇëÏÈÈ·ÈÏÄãÓÐÔÚ°²×°Ä¿Â¼´æµµµÄȨÏÞ¡£Í¨³£ÕâʱºòÒªÇл»Îª root £¬²ÅÄÜ°²×°´æµµ¡£

+ +

ÈôÄãÊÇÓà MS-Windows Ï嵀 ActivePerl £¬ make Çë¸ÄÓà nmake ¡£ nmake ¿ÉÓÉ΢ÈíµÄ FTP Õ¾ÏÂÔØ¡£

+ +

ÈôÒª°²×°µ½ÆäËüµØ·½£¬ÇëÉ趨ºÃ PREFIX ¡£ÀýÈ磬һ°ãʹÓÃÕߣ¬Òª°²×°ÔÚ×Ô¼ºµÄĿ¼ÏÂʱ£º

+ +
+% perl Makefile.PL PREFIX=/home/jessica
+
+ +

ÒªÖªµÀ¸ü¶à°²×°Ñ¡ÏîµÄϸ½Ú£¬Çë²ÎÔÄ ExtUtils::MakeMaker µÄ˵Ã÷£¨ÇëÖ´ÐÐ perldoc ExtUtils::MakeMaker £©¡£

+ + +

ÒÔ Module::Build °²×°

+ +

ÈôÄãϲ»¶£¬Ò²¿ÉÒÔÓà Module::Build °²×°£¬³ÌÐòÈçÏ£º

+ +
+% perl Build.PL
+% ./Build
+% ./Build test
+% ./Build install
+
+ +

ÔÚ ./Build install Ç°£¬ÇëÏÈÈ·ÈÏÄãÓÐÔÚ°²×°Ä¿Â¼´æµµµÄȨÏÞ¡£Í¨³£ÕâʱºòÒªÇл»Îª root £¬²ÅÄÜ°²×°´æµµ¡£

+ +

ÈôÒª°²×°µ½ÆäËüµØ·½£¬ÇëÉ趨ºÃ --prefix ¡£ÀýÈ磬һ°ãʹÓÃÕߣ¬Òª°²×°ÔÚ×Ô¼ºµÄĿ¼ÏÂʱ£º

+ +
+% perl Build.PL --prefix=/home/jessica
+
+ +

ÒªÖªµÀ¸ü¶à°²×°Ñ¡ÏîµÄϸ½Ú£¬Çë²ÎÔÄ Module::Build µÄ˵Ã÷£¨ÇëÖ´ÐÐ perldoc Module::Build £©¡£

+ + +

ÃüÁîÁвÎÊý

+ +
+./arclog [²ÎÊý] ¼Ç¼µµµµÃû… [¹éµµµµÃû¿ªÍ·]
+./arclog [-h|-v]
+
+ + +
+
¼Ç¼µµµµÃû
+ +
+

ÒªÕûÀí¹éµµµÄ¼Ç¼µµµµÃû¡£ÈôÒª´Ó±ê×¼ÊäÈë¶Á¼Ç¼µµ£¬ÇëÉ趨³É - ¡£¿Éͬʱָ¶¨Ðí¶àµµ°¸¡£Ö§Ô® gzip »ò bzip2 ѹËõµµ¡£

+
+ + +
¹éµµµµÃû¿ªÍ·
+ +
+

¹éµµµµÃûÓõĿªÍ·£¬¹éµµºóµÄµµ°¸»áÈ¡Ãû½Ð¿ªÍ·.yymmdd£¬È磺¿ªÍ·.200101 ¡¢¿ªÍ·.200102 …µÈ¡£Èç¹ûûÓÐÉ趨£¬»áÓüǼµµµÄµµÃûµ±¿ªÍ·¡£ÈôÄãÒª´Ó±ê×¼ÊäÈë¶Á¼Ç¼µµ£¬¾ÍÒ»¶¨ÒªÉè¹éµµµµÃû¿ªÍ·¡£ÕâÀï²»ÄÜÓà - £¨±ê×¼ÊäÈ룩£¬ÒòΪÕâÀïÉ趨µÄÊǵµÃûµÄ¿ªÍ·£¬²»ÊǵµÃû¡£

+
+ + +
-c, --compress ѹËõ·¨
+ +
+

É趨¹éµµÓõÄѹËõ·¨¡£¼Ç¼´ó¶à¶¼³¤µÃºÜÏñ£¬Ñ¹Ëõµô»áÊ¡Ï·dz£¶àµÄ¿Õ¼ä¡££¨²»È»¸ÉÂï¹éµµ£¿ ^_*’ £©Ä¿Ç°Ö§Ô®ÏÂÁеÄѹËõ·¨£º

+ + +
+
g, gzip
+ +
+

Óà gzip ѹËõ¡£Ô¤ÉèÊÇÓà gzip ѹËõ¡£ arclog ¿ÉÒÔÓà Compress::Zlib À´´úÌæ gzip ѹËõ£¬²»Óúô½ÐÍⲿ³Ìʽ£¬±È½Ï¿ì±È½Ï°²È«¡£²»¹ýÈç¹ûÄãûÓÐ×° Compress::Zlib £¬ arclog »¹ÊÇ»á×Ô¼º¸ÄÓà gzip ³ÌʽѹËõ¡£µ«Èç¹ûÁ¬ gzip ³Ìʽ¶¼Ã»ÓУ¬È´ÒªÓõ½ gzip ѹËõ£¬¾ÍûÓа취ÁË£¬ÎÞ·¨Ö´ÐС£

+
+ + +
b, bzip2
+ +
+

Óà bzip2 ѹËõ¡£ arclog ¿ÉÒÔÓà Compress::Bzip2 À´´úÌæ bzip2 ѹËõ£¬²»Óúô½ÐÍⲿ³Ìʽ£¬±È½Ï¿ì±È½Ï°²È«¡£²»¹ýÈç¹ûÄãûÓÐ×° Compress::Bzip2 £¬ arclog »¹ÊÇ»á×Ô¼º¸ÄÓà bzip2 ³ÌʽѹËõ¡£µ«Èç¹ûÁ¬ bzip2 ³Ìʽ¶¼Ã»ÓУ¬È´ÒªÓõ½ bzip2 ѹËõ£¬¾ÍûÓа취ÁË£¬ÎÞ·¨Ö´ÐС£

+
+ + +
n, none
+ +
+

²»ÒªÑ¹Ëõ¡££¨Äãû¸ã´í°É£¿ :p £©

+
+
+
+ + +
--nocompress
+ +
+

¹éµµºó²»ÒªÑ¹Ëõ£¬Ð§¹ûºÍ --compress none Ò»Ñù¡£

+
+ + +
-s, --sort
+ +
+

°´¼Ç¼ʱ¼äÏȺ󣨼°¼Ç¼±¾Éí˳Ðò£©ÅÅÐò¡£ÅÅÐòºÜºÄ¼ÇÒäÌåºÍ CPU £¬ËùÒÔÔ¤ÉèÊDz»ÅÅÐò¡£Çë²Î¼ûÇ°Ãæ¹Øì¶ÅÅÐòµÄ×¢ÒâÊÂÏî¡£

+
+ + +
--nosort
+ +
+

²»ÒªÅÅÐò£¨Ô¤ÉèÖµ£©¡£

+
+ + +
-o, --override ģʽ
+ +
+

Èç¹ûÓÐͬÃûµÄ¾Éµµ£¬¸ÃÔõô°ì¡£Ä¿Ç°ÓÐÏÂÁÐģʽ£º

+ + +
+
o, overwrite
+ +
+

¸Çµô¾Éµµ¡£¾ÉµµµÄ¼Ç¼»á±»É¾µô£¬Çë¶à¼ÓСÐÄ¡£ÈôÄãµÄ¼Ç¼µµÊÇÖ÷¼Ç¼µµ£¬ÓÐ×îÍêÕûµÄ¼Ç¼£¬Äã¿ÉÒÔÓà overwrite ¡£

+
+ + +
a, append
+ +
+

ºÍ¾Éµµ¼ÓÔÚÒ»Æð¡£ÕâÓпÉÄÜ»áÑݱä³É´ó»ìÂÒ£¬Çë¶à¼ÓСÐÄ¡£ÈôÄãÏë°ÑÁ½·Ý²»Í¬Ê±¼äµÄ¼Ç¼µµ¼ÓÔÚÒ»Æð£¬Äã¿ÉÒÔÓà append ¡£

+
+ + +
i, ignore
+ +
+

ÂÔ¹ýËùÓиÃÔµļǼ¡£ÕâÓпÉÄÜÔì³É²¿·Ý¼Ç¼Á÷ʧ£¬Çë¶à¼ÓСÐÄ¡£ÈôÄãÖ»Òª²¹³äûÓй鵵µÄÔ·ݣ¬Äã¿ÉÒÔÓà ignore ¡£

+
+ + +
f, fail
+ +
+

½áÊø³Ìʽ£¬ÒÔÃⲻСÐÄÆÆ»µ¾Éµµ¡£ÈôÄãÒªÓà crontab Ö®ÀàµÄ³Ìʽ£¬È«×Ô¶¯»¯Ö´ÐУ¬×îºÃÕâÑù£¬ÒÔÃâÆÆ»µ×ÊÁÏ¡£Òò´Ë£¬Èô±ê×¼ÊäÈë²»ÊÇÁ¬µ½¼üÅÌÉÏ£¬Ô¤ÉèÊÇ fail ¡£

+
+ + +
ask
+ +
+

ÎÊÄã¸ÃÔõô°ì¡£ÈôÄãÊÇÊÖ¶¯Ö´ÐУ¬ÕâÑù×î·½±ã¡£Òò´Ë£¬Èô±ê×¼ÊäÈëÊÇÁ¬µ½¼üÅÌÉÏ£¬Ô¤ÉèÊÇ ask ¡£´ð°¸ÊÇ´Ó±ê×¼ÊäÈë¶ÁµÄ¡£ÒòΪ±ê×¼ÊäÈëÖ»ÓÐÒ»¸ö£¬ÈôÄãÒª´Ó±ê×¼ÊäÈë¶Á¼Ç¼µµ£¬²»ÄÜÅÜ ask ģʽ£¬»á×Ô¶¯ÍË»Ø fail ģʽ¡£»¹ÓУ¬Èç¹û´Ó±ê×¼ÊäÈë¶Á²»µ½¶«Î÷£¬Ïñ crontab Àï±ê×¼ÊäÈë±»¹ØµôÁË£¬Ò²»á×Ô¶¯ÍË»Ø fail ģʽ¡£

+
+
+
+ + +
-k, --keep ģʽ
+ +
+

Ô­¼Ç¼µµÒªÔõô´¦Àí¡£Ä¿Ç°ÓÐÏÂÁÐģʽ£º

+ + +
+
a, all
+ +
+

ÍêÈ«±£ÁôÔ­µµ¡£

+
+ + +
r, restart
+ +
+

¹éµµºó£¬Ô­¼Ç¼µµ¹éÁã¡£

+
+ + +
d, delete
+ +
+

¹éµµºó£¬É¾³ýÔ­¼Ç¼µµ¡£

+
+ + +
t, this-month
+ +
+

½«Ö®Ç°Ô·ݵļǼ¹éµµ£¬±£ÁôÕâ¸öÔµļǼ£¬Áô´ýϸöÔ¹鵵¡£ÕâÊǸø crontab ÿÔ¹鵵Óõġ£Òò´Ë£¬Ô¤ÉèÊÇ this-month ¡£

+
+
+ +
+ + +
-d, --debug
+ +
+

ÏÔʾÏêϸµÄÖ´Ðйý³Ì¡£

+
+ + +
-q, --quiet
+ +
+

ûʲ»Òª³³¡£ :p

+
+ + +
-h, --help
+ +
+

ÏÔʾ³Ìʽ˵Ã÷¡£

+
+ + +
-v, --version
+ +
+

ÏÔʾ³Ìʽ°æ±¾¡£

+
+
+ + +

°æȨÉùÃ÷

+ +

°æȨËùÓÐ © 2001-2007 ÒÀÂêè¡£

+ +

±¾³ÌʽÊÇ×ÔÓÉÈíÌ壬Äú¿ÉÒÔ×ñÕÕ×ÔÓÉÈíÌå»ù½ð»á (Free Software Foundation) ³ö°æµÄ GNU ͨÓù«¹²Ðí¿ÉÖ¤Ìõ¿î (GNU General Public License) µÚÈý°æÀ´Ð޸ĺÍÖØз¢²¼ÕâÒ»³Ìʽ£¬»òÕß×ÔÓÉÑ¡ÔñʹÓÃÈκθüеİ汾¡£

+ +

·¢²¼ÕâÒ»³ÌʽµÄÄ¿µÄÊÇÏ£ÍûËüÓÐÓ㬵«Ã»ÓÐÈκε£±£¡£ÉõÖÁûÓÐÊʺÏÌض¨Ä¿µÄ¶øÒþº¬µÄµ£±£¡£¸üÏêϸµÄÇé¿öÇë²ÎÔÄ GNU ͨÓù«¹²Ðí¿ÉÖ¤¡£

+ +

ÄúÓ¦¸ÃÒѾ­ºÍ³ÌʽһÆðÊÕµ½Ò»·Ý GNU ͨÓù«¹²Ðí¿ÉÖ¤µÄ¸±±¾¡£Èç¹û»¹Ã»ÓУ¬²ÎÔÄ<http://www.gnu.org/licenses/>¡£

+ + +

°æ±¾¼Í¼

+ +

ÇëÔĶÁ NEWS µµ£¬²é¿´³ÌʽµÄÑݱ䡢ÐÂÔöµÄ¹¦ÄܺÍÐÞ²¹µÄ´íÎó¡£

+ + +

֧ԮЭÖú

+ +

arclog ÍøÕ¾¼ÜÔÚ SourceForge ¡¢ CPAN Óë ÂÃÉáÒÀÂê¡£Ë÷È¡×îÐÂ×ÊѶ£¬Çë¼ÝÁÙ£º

+ + + +

ÔÚ SourceForge ÉÏÓÐÒ»¸ö arclog µÄÓʼþͨѶ ¡£Ê¹ÓÃÉϵÄÎÊÌâ¡¢½¨Òé»ò´íÎó»Ø±¨£¬ÇëÌᵽͨѶÉÏÌÖÂÛ¡£ËüÊÇ Mailman µÄÓʼþͨѶ¡£ÈôÒª¼ÓÈ룬Çëµ½ arclog ÓʼþͨѶµÄÍøÒ³ ¡£ÄãÒ²¿ÉÒÔдÐŵ½ E-mail Ö¸ÁîÐÅÏ䣬±êÌâÌîÉÏ help £¬Ë÷È¡ E-mail Ö¸Áî˵Ã÷¡£

+ +
+ + +
+ + + + diff --git a/arclog.zh-tw.html b/arclog.zh-tw.html new file mode 100644 index 0000000..6542f99 --- /dev/null +++ b/arclog.zh-tw.html @@ -0,0 +1,515 @@ + + + + + + + + + + + + + + + +arclog 3.04 ª© + + + +
+ ¥¿Å餤¤å | + 简Ê^¤¤¤å | + English +
+
+ + +
+ + +

arclog 3.04 ª©

+ + +

³Ì·s®ø®§

+ +
+
2007-12-03
+ +
+

arclog ³Ì·sª©¥» 3.04 ¡C»¡©ú¤å¥ó­×¥¿¡C­Y©p¤§«e¦w¸Ë¤F arclog 3.00 ª©©Î¤§«áªºª©¥»¡A¤£»Ý­nª@¯Å·sª©¡C¤U¸ü arclog 3.04 ª©¡C

+
+ + +
2007-12-03
+ +
+

arclog ³Ì·sª©¥» 3.03 ¡C­×¥¿´ú¸Õ®M¥ó¡C©Ò»Ý Perl ª©¥»¸¹½X§ï¥Î¬Û®e©óª©ªº¸¹½X®æ¦¡¡A¥H®ø°£ Perl 5.10 ªºÄµ§i°T®§¡C­Y©p¤§«e¦w¸Ë¤F arclog 3.00 ª©©Î¤§«áªºª©¥»¡A¤£»Ý­nª@¯Å·sª©¡C¤U¸ü arclog 3.03 ª©¡C

+
+ + +
2007-11-30
+ +
+

arclog ³Ì·sª©¥» 3.02 ¡C­×¥¿´ú¸Õ®M¥ó¡A¥H³B²z¤é¥ú¸`¬ù®É¶¡°ÝÃD¡C­Y©p¤§«e¦w¸Ë¤F arclog 3.00 ª©©Î¤§«áªºª©¥»¡A¤£»Ý­nª@¯Å·sª©¡C¤U¸ü arclog 3.02 ª©¡C

+
+ + +
2007-11-28
+ +
+

arclog ³Ì·sª©¥» 3.01 ¡C­×¥¿´ú¸Õ®M¥ó¡A¥H¨ó§UÂç²M CPAN ´ú¸Õ¦^³øªº¿ù»~¡C­Y©p¤§«e¦w¸Ë¤F arclog 3.00 ª©¡A¤£»Ý­nª@¯Å·sª©¡C¤U¸ü arclog 3.01 ª©¡C

+
+ + +
2007-11-28
+ +
+

arclog ³Ì·sª©¥» 3.00 ¡C±q reslog ­É¹L¨Óªº¥þ·sµ{¦¡½X¡AÀɦW¤]±q arclog.pl §ï¬° arclog ¡C·sªºª«¥ó¾É¦V³B²z¾¹¡A¥i¶¶§Q³B²z¦UºØÀ£ÁYªk¤ÎÀɮ׮榡¡C¦w¸Ë¨t²Î¥Ñ GNU autoconf §ï¥Î Perl ªº ExtUtils::MakeMaker ©M Module::Build ¡C·s¥[¤W§¹¾ãªº´ú¸Õ®M¥ó¡A¨ó§Uµ{¦¡«~ºÞ¡Cª©Åv§ó·s¬° GPLv3 ¡C¤U¸ü arclog 3.00 ª©¡C

+
+ + +
2002-09-26
+ +
+

arclog.pl ³Ì·sª©¥» 2.1.0 ¡C³o¬O 2.1.0 ªº³Ì²×ª©¡A¥[¤W¤F bzip2 À£ÁYªº¤ä´©¡A¥Î gzip µ{¦¡¥N´À Compress::Zlib À£ÁY¡A¨Ã§ï¥Î GNU autoconf ¦w¸Ë³]©wµ{¦¡¡C¤U¸ü arclog.pl 2.1.0 ¡C

+
+ + +
2002-09-18
+ +
+

arclog.pl ³Ì·sª©¥» 2.1.0dev2 ¡C¥»ª©­×¥¿¤F´X­Ó»¡©ú¤å¥óªº¿ù»~¡A¨Ã§â SourceForge ¥[¶i arclog.pl ªº¤U¸üºô§}¤¤¡C©p¥i¥H§â¥¦·í°µ¥Ó½Ð SourceForge ¬ö©Àª©¡C­ì«h¤W¡A¤£»Ý­n«æµÛª@¯Å¡C¤U¸ü arclog.pl 2.1.0dev2 ¡C

+
+ + +
2002-09-17
+ +
+

¦n®ø®§¡I arclog.pl ¤w¶}©l¬[³]©ó SourceForge Åo¡I¡]ÁöµM§Ú´X¥GÁÙ§¹¥þ·d¤£²M·¡­n«ç»ò¬[¡KºN¯Á¤¤¡K ^^; ¡^

+
+
+ + + +

»¡©ú

+ +

arclog ¬O°O¿ýÀɨC¤ëÂkÀɵ{¦¡¡A±N°O¿ýÀɤ¤¡A«e¤ëªº°O¿ý«ö¤ë¥÷À£ÁYÂkÀÉ¡A¥H¸`¬ÙµwºÐªÅ¶¡¡A¨ÃÁקK°O¿ýÀɳQ¦³¤ß¤H¤h¯}Ãa¡C

+ +

arclog ¥Ø«e¤ä´© Apache ¡B Syslog ¡B NTP ¡B Apache 1 SSL engine log ¤Î§Ú¦Û¤v¥Îªº¬A©· ISO ­×¥¿®æ¦¡¤­ºØ®æ¦¡ªº°O¿ýÀÉ¡A»P gzip ©M bzip2 ¨âºØÀ£ÁYªk¡C«Ü¦hµ{¦¡³£¥i¥H¥Î Apache ¬Û®e°O¿ýÀɮ榡°O¿ý¡A¦p CUPS ¡B ProFTPD ¡B Pure-FTPd…µ¥¡A arclog ¤]¥i¥HÂkÀɳo¨Ç Apache ¬Û®e®æ¦¡ªº°O¿ýÀÉ¡C

+ + +

ª`·N¨Æ¶µ

+ +
    +
  • ÂkÃþ°O¿ýÀɫܯӮɶ¡¡C¬°´î¤Ö¦û¥Î­ì°O¿ýÀɪº®É¶¡¡A arclog ·|¥ý§â­ì°O¿ýÀɽƻs¨ì¼È®É¤u§@ÀÉ¡Aµø»Ý­n§â­ì°O¿ýÀÉÂk¹s¡A¦AºCºC¦b¼È®É¤u§@ÀɤW§@·~¡C¤£¹L¤´½Ðª`·N¤U¦C¨Æ¶µ¡G

    +
      +
    1. ¦pªG­ì°O¿ýÀɫܤj¡]¦n´X¦Ê MB ¡^¡A¥ú½Æ»sÀÉ®×´N«Üªá®É¶¡¤F¡C³oºØ±¡ªp¤U¡A³Ì¦n¥ýÃö³¬°O¿ýµ{¦¡¡Aµ¥¾ã²z§¹¥H«á¡A¦AÄ~Äò°O¿ý¡A¥HÁקK°O¿ý¿ù¶Ã¡C­Y¥­±`¦³©w´ÁÂkÀÉ¡A°O¿ýÀÉ´N¤£·|µL­­¨î¿±µÈ¤F¡C

    2. +
    3. ­Y arclog °õ¦æ¨ì¤@¥b¦]¬G¤¤Â_¡A·|¯d¤U´Ý¦sªº¼È®É¤u§@ÀÉ¡C¤é«á arclog °õ¦æ®É¡A¸I¨ì¤§«e´Ý¦sªº¼È®É¤u§@ÀÉ¡A·|°±¤î°õ¦æ¡C­n¥ý³B²z±¼¤§«eªº¼È®É¤u§@ÀÉ¡A¤~¯àÄ~Äò¡C¼È®É¤u§@ÀÉ¥u¬O­ìÀɪº½Æ¥»¡A¥u­n§ï­ÓÀɦW¦AÂkÀɤ@¦¸¡A´N¥i¥H¤F¡C

    4. +
    +
  • + +
  • ¨S¦³¯S§O²z¥Ñ¡A³Ì¦n¤£­n±Æ§Ç¡C±Æ§Çªº¼ç¦b°ÝÃD¦p¤U¡G

    +
      +
    1. °O¿ýÀɫܤj®É¡A±Æ§Ç·|¦Y±¼«Ü¦h°O¾ÐÅé¡C©Ò»Ý°O¾ÐÅé¨ÌÂkÀÉ«á¨C­Ó¤ë°O¿ýµ§¼Æ¦Ó©w¡C·sª©ªº Linux ©M MS-Windows ¨t²Î¦³°O¾ÐÅé¯Ó¥Î«OÅ@¡A·|¤¤Â_¦Y±¼¤Ó¦h°O¾ÐÅ骺µ{¦¡¡A¤£¹L³oÁÙ¬O­nªá¦n´X¤ÀÄÁ¡A³o´X¤ÀÄÁ¤º¨t²Î·|§¹¥þ·í±¼¤£°Ê¡C§Ú¤£ª¾¹D§Oªº§@·~¨t²Î¦³¨S¦³°O¾ÐÅé¯Ó¥Î«OÅ@¡C¦pªG©p­nª±¡A­·ÀI¦Û­t¡C

    2. +
    3. ©Ò¦³¤ä´©ªº°O¿ýÀɮ榡¡A®É¶¡³Ì¤p³æ¦ì¬°¬í¡C¦P¤@¬í¤ºªº°O¿ý·|¥ý¥H°O¿ýÀɶ¶§Ç¡]­Y¦P®ÉÂkÀɦn´X­Ó°O¿ýÀÉ¡^¡A¦A¥H°O¿ý¥»¨­¥X²{ªº¦¸§Ç±Æ§Ç¡C³o¼Ë³]­p¾¨¥i¯àÅý±Æ§ÇÂkÀÉ«á¦P¤@¬í¤ºªº°O¿ý¦¸§Ç¡A©M¨Æ¥ó¯u¥¿ªºµo¥Í¶¶§Ç¤@­P¡A¦ý¤]µLªk§¹¥þ«OÃÒ¡C­Y¦P¤@¬í¤ºªº¨Æ¥ó¦¸§Ç«Ü­«­n¡A©p­n¦Û¦æ¤p¤ß¡C

    4. +
    +
  • + +
  • ÂkÀÉ Syslog ©M NTP °O¿ýÀɮɡA½Ð¯S§Oª`·N¡G Syslog ©M NTP °O¿ýÀɨS¦³°O¦~¡C arclog ¥Î Date::Parse ¼Ò²Õ¸ÑŪ®É¶¡¡CµL¦~¥÷®É¡A Date::Parse ·|§â¦~¥÷³]¦b³o­Ó¤ë¨ì¥h¦~ªº¤U­Ó¤ë¤§¶¡¡C¨Ò¦p¡A­Y¤µ¤Ñ¬O 2001-06-08 ¡A¨º¦~¥÷·|³]¦b 2001-06-30 ¨ì 2000-07-01 ¤§¶¡¡C§Ú­ì«h¤WÃÙ¦¨³o¼Ë¡C¤£¹L¡A­Y©pªº Syslog ©Î NTP °O¿ýÀɶW¹L¤@¦~¾ã²zÂkÀÉ¡A¤£­n¶] arclog ¡A§_«h°O¿ýÀÉ·|¤j¶Ã¡C

  • + +
  • ±q¼Ð·Ç¿é¤JŪ°O¿ýÀÉ¡A½Ðª`·N¤U¦C¨Æ¶µ¡G

    +
      +
    1. ­Y­nŪ¼Ð·Ç¿é¤J¡A´N¤@©w­n³]©wÂkÀɮɡAÀɦWªº¶}ÀY¡A¤£µM¤£ª¾¹D«ç»òÂkÀÉ«á­n¦s¨ì­þùØ¥h¡C

    2. +
    3. ¼Ð·Ç¿é¤JµLªk§R°£¡BÂk¹s©Î«O¯d³¡¥÷¤º®e¡C­Y­nŪ¼Ð·Ç¿é¤J¡A­ìÀÉ«O¯d¼Ò¦¡·|¦Û°Ê°h¦^¦¨¥þ³¡«O¯d¡C¤@¦¸Åª¤J¦hÀɮɡA­Y¨ä¤¤¦³¼Ð·Ç¿é¤J¡A·|¤@«ß°h¦^¥þ³¡«O¯d¡A¥HÁקK²V¶Ã¡C

    4. +
    5. ask ¼Ò¦¡ªº¦^µª¤]¬O±q¼Ð·Ç¿é¤JŪªº¡C¦]¬°¼Ð·Ç¿é¤J¥u¦³¤@­Ó¡A©Ò¥H±q¼Ð·Ç¿é¤JŪÀɮɡAµLªk¶] ask ¼Ò¦¡¡A·|¦Û°Ê°h¦^¨ì fail ¼Ò¦¡¡C

    6. +
    +
  • + +
  • §Ú«Øij¦w¸Ë File::MMagic ¡A¾¨¶q¤£­n¥Î file µ{¦¡¡C File::MMagic ¤º«ØªºÀÉ®×Ãþ«¬ªí¦n¹³¤ñ file µ{¦¡·Ç½T¡C­Y¤£¬O gzip ©Î bzip2 À£ÁYÀÉ¡A arclog ·|§âµø¬°·í¦¨¯Â¤å¦rÀÉ¡C­YÀ£ÁYÀɳQ»~§P¬°¹ÏÀÉ¡A arclog ·|·í¦¨¯Â¤å¦rÀÉ¡Aª½±µÅª°O¿ý¡A¨Ã¥H¿ù»~µ²§ô¡C´Nºâ¿ù»~¤]¤£·|§Ë¶Ã­ì°O¿ýÀÉ¡A¤£¹L¦h¤Ö¦³ÂI³Â·Ð¡C

  • +
+ + +

¨t²Î»Ý¨D

+ +
    +
  1. Perl 5.8.0 ¥H¤W¡C arclog ¥Î¤T­Ó°Ñ¼Æªº open() ¨Ó½Æ»sÀÉ®×¾Þ§@¡A§ÚÁÙ¤£ª¾¹D«ç»ò§ï¼g¨ì§ó¦­ªºª©¥»¤W°õ¦æ¡C­Y©p¥i¥H§ï¼g¨ì§ó¦­ªºª©¥»¤W°õ¦æ¡A½Ð§i¶D§Ú¡C©p¥i¥H¿é¤J perl -v ¬d¸ß©p¥Ø«eªº Perl ª©¥»¡C¦pªG©p¨S¦³ Perl ©Î»Ý­nª@¯Å¡A¥i¥H¨ì Perl ºô¯¸¤U¸ü¦w¸Ë³Ì·sª© Perl ¡C­Y©p¬O¥Î MS-Windows ¡A¥i¥H¨ì ActiveState ¤½¥q¤U¸ü ActivePerl ¦w¸Ë¡C

  2. + +
  3. »Ý·f°tªº Perl ¼Ò²Õ¡G

    + +
    +
    Date::Parse
    + +
    +

    ³o¬O¿ëÃÑ°O¿ý®É¶¡¥Îªº¡C©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Date::Parse ¡A©Î¥Î CPAN Shell °õ¦æ cpan Date::Parse ¦w¸Ë¡A©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Date::Parse ¦w¸Ë¡C­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ apt-get install libtimedate-perl ¦w¸Ë¡C­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ yum install perl-TimeDate ¦w¸Ë¡C­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ports install p5-TimeDate ¦w¸Ë¡C­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ppm install Date::Parse ¦w¸Ë¡C

    +
    +
    + +

    ­Y©p¥Ñ CPAN ©Î CPANPLUS Shell ¦w¸Ë arclog ¡A·|¦Û°ÊÀ°©p¦w¸Ë¥H¤W©Ò»Ýªº¼Ò²Õ¡C

    +
  4. + +
  5. ¿ï°tªº Perl ¼Ò²Õ¡G

    + +
    +
    File::MMagic
    + +
    +

    ³o¬OÀˬdÀÉ®×Ãþ«¬¥Îªº¡C­Y¨S¦³¦w¸Ë¡A arclog ·|§ä file µ{¦¡¥N´À¡C­YÁ٧䤣¨ì¡A arclog ·|§ï¥ÎÀɧÀ¡]°ÆÀɦW¡^§PÂ_ÀÉ®×Ãþ«¬¡C³o®É­Y±q¼Ð·Ç¿é¤JŪÀÉ¡A arclog ´NµLªk§PÂ_¤F¡C©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë File::MMagic ¡A©Î¥Î CPAN Shell °õ¦æ cpan File::MMagic ¦w¸Ë¡A©Î¥Î CPANPLUS Shell °õ¦æ cpanp i File::MMagic ¦w¸Ë¡C­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ apt-get install libfile-mmagic-perl ¦w¸Ë¡C­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ yum install perl-File-MMagic ¦w¸Ë¡C­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ports install p5-File-MMagic ¦w¸Ë¡C­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ppm install File::MMagic ¦w¸Ë¡C­Y©p­n¦b MS-Windows ¤U¨Ï¥Î file.exe µ{¦¡¡A¥i¥H¥Ñ GnuWin32 ºô¯¸¤U¸ü¡C½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° file.exe ¡C

    + +

    «Øij¥Î File::MMagic ¡C file µ{¦¡°¸º¸·|»~§P¡C

    +
    + +
    Compress::Zlib
    + +
    +

    ³o¬O³B²z gzip À£ÁYÀɥΪº¡A¥u¦³¦b³B²z gzip À£ÁYÀɤ~·|¥Î¨ì¡C­Y­n¥Î®É¨S¦³¦w¸Ë¡A arclog ·|¸ÕµÛ§ï¥Î gzip µ{¦¡¥N´À¡C­YÁ٧䤣¨ì¡A arclog ´NµLªk°õ¦æ¡C©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Compress::Zlib ¡A©Î¥Î CPAN Shell °õ¦æ cpan Compress::Zlib ¦w¸Ë¡A©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Compress::Zlib ¦w¸Ë¡C­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ apt-get install libcompress-zlib-perl ¦w¸Ë¡C­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ yum install perl-Compress-Zlib ¦w¸Ë¡C­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ports install p5-Compress-Zlib ¦w¸Ë¡C­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ppm install Compress::Zlib ¦w¸Ë¡C­Y©p­n¦b MS-Windows ¤U¨Ï¥Î gzip.exe µ{¦¡¡A¥i¥H¥Ñ gzip ºô¯¸¤U¸ü¡C½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° gzip.exe ¡C

    +
    + +
    Compress::Bzip2 ²Ä¤Gª©¥H¤W
    + +
    +

    ³o¬O³B²z bzip2 À£ÁYÀɥΪº¡A¥u¦³¦b³B²z bzip2 À£ÁYÀɤ~·|¥Î¨ì¡C­Y­n¥Î®É¨S¦³¦w¸Ë¡A arclog ·|¸ÕµÛ§ï¥Î bzip2 µ{¦¡¥N´À¡C­YÁ٧䤣¨ì¡A arclog ´NµLªk°õ¦æ¡C©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Compress::Bzip2 ¡A©Î¥Î CPAN Shell °õ¦æ cpan Compress::Bzip2 ¦w¸Ë¡A©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Compress::Bzip2 ¦w¸Ë¡C­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ apt-get install libcompress-bzip2-perl ¦w¸Ë¡C­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ yum install perl-Compress-Bzip2 ¦w¸Ë¡C­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ports install p5-Compress-Bzip2 ¦w¸Ë¡C­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ppm install Compress::Bzip2 ¦w¸Ë¡C­Y©p­n¦b MS-Windows ¤U¨Ï¥Î bzip2.exe µ{¦¡¡A¥i¥H¥Ñ bzip2 ºô¯¸¤U¸ü¡C½Ð½T»{¤U¸ü«á¡A¦sÀɦb¨t²Îªº¸ô®|¤U¡AÀɦW¬° bzip2.exe ¡C

    +
    + +
    Term::ReadKey
    + +
    +

    ³o¬OÅã¥Ü¶i«×¦C¥Îªº¡A­Y¨S¦³¦w¸Ë¡A´N¤£·|Åã¥Ü¶i«×¦C¡C¦¹¥~¤£·|¦³¥ô¦ó°ÝÃD¡C¶i«×¦C¥i¥HÅý©p¹ï arclog ªº¤u§@¶i«×¤@¥ØÁAµM¡C©p¥i¥H¥Ñ CPAN ¼Ò²Õ®w¤U¸ü¦w¸Ë Term::ReadKey ¡A©Î¥Î CPAN Shell °õ¦æ cpan Term::ReadKey ¦w¸Ë¡A©Î¥Î CPANPLUS Shell °õ¦æ cpanp i Term::ReadKey ¦w¸Ë¡C­Y©p¬O Debian/Ubandu Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ apt-get install libterm-readkey-perl ¦w¸Ë¡C­Y©p¬O Red Hat/Fedora/CentOS Linux ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ yum install perl-TermReadKey ¦w¸Ë¡C­Y©p¬O FreeBSD ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ports install p5-Term-ReadKey ¦w¸Ë¡C­Y©p¬O ActivePerl ¨Ï¥ÎªÌ¡A¥i¥H°õ¦æ ppm install Term::ReadKey ¦w¸Ë¡C

    +
    +
    +
  6. +
+ + +

¤U¸ü

+ +

arclog ªº©x¤èºô¯¸¦b¡G

+ + + +

³Ì·sª© arclog ¥i¥Ñ¤U¦C¦ì§}¤U¸ü¡G

+ + + +

¨Ìº¿¿ßªº PGP ¤½Æ_¦b¡G

+ + + + +

¦w¸Ë

+ +

­Y©p¬O¥Ñ arclog.pl 2.1.1dev4 ¥H«eªºª©¥»ª@¯Å¡A½Ð°Ñ¾\ UPGRADE.zh-tw Àɪºª@¯Å»¡©ú¡C

+ +

¥H ExtUtils::MakeMaker ¦w¸Ë

+ +

arclog ¥Î Perl ¼Ð·Çªº ExtUtils::MakeMaker ¦w¸Ë¡Aµ{§Ç¦p¤U¡G

+ +
+% perl Makefile.PL
+% make
+% make test
+% make install
+
+ +

¦b make install «e¡A½Ð¥ý½T»{©p¦³¦b¦w¸Ë¥Ø¿ý¦sÀɪºÅv­­¡C³q±`³o®É­Ô­n¤Á´«¬° root ¡A¤~¯à¦w¸Ë¦sÀÉ¡C

+ +

­Y©p¬O¥Î MS-Windows ¤Uªº ActivePerl ¡A make ½Ð§ï¥Î nmake ¡C nmake ¥i¥Ñ·L³nªº FTP ¯¸¤U¸ü¡C

+ +

­Y­n¦w¸Ë¨ì¨ä¥¦¦a¤è¡A½Ð³]©w¦n PREFIX ¡C¨Ò¦p¡A¤@¯ë¨Ï¥ÎªÌ¡A­n¦w¸Ë¦b¦Û¤vªº¥Ø¿ý¤U®É¡G

+ +
+% perl Makefile.PL PREFIX=/home/jessica
+
+ +

­nª¾¹D§ó¦h¦w¸Ë¿ï¶µªº²Ó¸`¡A½Ð°Ñ¾\ ExtUtils::MakeMaker ªº»¡©ú¡]½Ð°õ¦æ perldoc ExtUtils::MakeMaker ¡^¡C

+ + +

¥H Module::Build ¦w¸Ë

+ +

­Y©p³ßÅw¡A¤]¥i¥H¥Î Module::Build ¦w¸Ë¡Aµ{§Ç¦p¤U¡G

+ +
+% perl Build.PL
+% ./Build
+% ./Build test
+% ./Build install
+
+ +

¦b ./Build install «e¡A½Ð¥ý½T»{©p¦³¦b¦w¸Ë¥Ø¿ý¦sÀɪºÅv­­¡C³q±`³o®É­Ô­n¤Á´«¬° root ¡A¤~¯à¦w¸Ë¦sÀÉ¡C

+ +

­Y­n¦w¸Ë¨ì¨ä¥¦¦a¤è¡A½Ð³]©w¦n --prefix ¡C¨Ò¦p¡A¤@¯ë¨Ï¥ÎªÌ¡A­n¦w¸Ë¦b¦Û¤vªº¥Ø¿ý¤U®É¡G

+ +
+% perl Build.PL --prefix=/home/jessica
+
+ +

­nª¾¹D§ó¦h¦w¸Ë¿ï¶µªº²Ó¸`¡A½Ð°Ñ¾\ Module::Build ªº»¡©ú¡]½Ð°õ¦æ perldoc Module::Build ¡^¡C

+ + +

©R¥O¦C°Ñ¼Æ

+ +
+./arclog [°Ñ¼Æ] °O¿ýÀÉÀɦW… [ÂkÀÉÀɦW¶}ÀY]
+./arclog [-h|-v]
+
+ + +
+
°O¿ýÀÉÀɦW
+ +
+

­n¾ã²zÂkÀɪº°O¿ýÀÉÀɦW¡C­Y­n±q¼Ð·Ç¿é¤JŪ°O¿ýÀÉ¡A½Ð³]©w¦¨ - ¡C¥i¦P®É«ü©w³\¦hÀɮסC¤ä´© gzip ©Î bzip2 À£ÁYÀÉ¡C

+
+ + +
ÂkÀÉÀɦW¶}ÀY
+ +
+

ÂkÀÉÀɦW¥Îªº¶}ÀY¡AÂkÀɫ᪺ÀÉ®×·|¨ú¦W¥s¶}ÀY.yymmdd¡A¦p¡G¶}ÀY.200101 ¡B¶}ÀY.200102 …µ¥¡C¦pªG¨S¦³³]©w¡A·|¥Î°O¿ýÀɪºÀɦW·í¶}ÀY¡C­Y©p­n±q¼Ð·Ç¿é¤JŪ°O¿ýÀÉ¡A´N¤@©w­n³]ÂkÀÉÀɦW¶}ÀY¡C³oùؤ£¯à¥Î - ¡]¼Ð·Ç¿é¤J¡^¡A¦]¬°³oùس]©wªº¬OÀɦWªº¶}ÀY¡A¤£¬OÀɦW¡C

+
+ + +
-c, --compress À£ÁYªk
+ +
+

³]©wÂkÀɥΪºÀ£ÁYªk¡C°O¿ý¤j¦h³£ªø±o«Ü¹³¡AÀ£ÁY±¼·|¬Ù¤U«D±`¦hªºªÅ¶¡¡C¡]¤£µM·F¹ÀÂkÀÉ¡H ^_*’ ¡^¥Ø«e¤ä´©¤U¦CªºÀ£ÁYªk¡G

+ + +
+
g, gzip
+ +
+

¥Î gzip À£ÁY¡C¹w³]¬O¥Î gzip À£ÁY¡C arclog ¥i¥H¥Î Compress::Zlib ¨Ó¥N´À gzip À£ÁY¡A¤£¥Î©I¥s¥~³¡µ{¦¡¡A¤ñ¸û§Ö¤ñ¸û¦w¥þ¡C¤£¹L¦pªG©p¨S¦³¸Ë Compress::Zlib ¡A arclog ÁÙ¬O·|¦Û¤v§ï¥Î gzip µ{¦¡À£ÁY¡C¦ý¦pªG³s gzip µ{¦¡³£¨S¦³¡A«o­n¥Î¨ì gzip À£ÁY¡A´N¨S¦³¿ìªk¤F¡AµLªk°õ¦æ¡C

+
+ + +
b, bzip2
+ +
+

¥Î bzip2 À£ÁY¡C arclog ¥i¥H¥Î Compress::Bzip2 ¨Ó¥N´À bzip2 À£ÁY¡A¤£¥Î©I¥s¥~³¡µ{¦¡¡A¤ñ¸û§Ö¤ñ¸û¦w¥þ¡C¤£¹L¦pªG©p¨S¦³¸Ë Compress::Bzip2 ¡A arclog ÁÙ¬O·|¦Û¤v§ï¥Î bzip2 µ{¦¡À£ÁY¡C¦ý¦pªG³s bzip2 µ{¦¡³£¨S¦³¡A«o­n¥Î¨ì bzip2 À£ÁY¡A´N¨S¦³¿ìªk¤F¡AµLªk°õ¦æ¡C

+
+ + +
n, none
+ +
+

¤£­nÀ£ÁY¡C¡]©p¨S·d¿ù§a¡H :p ¡^

+
+
+
+ + +
--nocompress
+ +
+

ÂkÀɫᤣ­nÀ£ÁY¡A®ÄªG©M --compress none ¤@¼Ë¡C

+
+ + +
-s, --sort
+ +
+

«ö°O¿ý®É¶¡¥ý«á¡]¤Î°O¿ý¥»¨­¶¶§Ç¡^±Æ§Ç¡C±Æ§Ç«Ü¯Ó°O¾ÐÅé©M CPU ¡A©Ò¥H¹w³]¬O¤£±Æ§Ç¡C½Ð°Ñ¨£«e­±Ãö©ó±Æ§Çªºª`·N¨Æ¶µ¡C

+
+ + +
--nosort
+ +
+

¤£­n±Æ§Ç¡]¹w³]­È¡^¡C

+
+ + +
-o, --override ¼Ò¦¡
+ +
+

¦pªG¦³¦P¦WªºÂÂÀÉ¡A¸Ó«ç»ò¿ì¡C¥Ø«e¦³¤U¦C¼Ò¦¡¡G

+ + +
+
o, overwrite
+ +
+

»\±¼ÂÂÀÉ¡CÂÂÀɪº°O¿ý·|³Q§R±¼¡A½Ð¦h¥[¤p¤ß¡C­Y©pªº°O¿ýÀɬO¥D°O¿ýÀÉ¡A¦³³Ì§¹¾ãªº°O¿ý¡A©p¥i¥H¥Î overwrite ¡C

+
+ + +
a, append
+ +
+

©MÂÂÀÉ¥[¦b¤@°_¡C³o¦³¥i¯à·|ºtÅܦ¨¤j²V¶Ã¡A½Ð¦h¥[¤p¤ß¡C­Y©p·Q§â¨â¥÷¤£¦P®É¶¡ªº°O¿ýÀÉ¥[¦b¤@°_¡A©p¥i¥H¥Î append ¡C

+
+ + +
i, ignore
+ +
+

²¤¹L©Ò¦³¸Ó¤ëªº°O¿ý¡C³o¦³¥i¯à³y¦¨³¡¥÷°O¿ý¬y¥¢¡A½Ð¦h¥[¤p¤ß¡C­Y©p¥u­n¸É¥R¨S¦³ÂkÀɪº¤ë¥÷¡A©p¥i¥H¥Î ignore ¡C

+
+ + +
f, fail
+ +
+

µ²§ôµ{¦¡¡A¥H§K¤£¤p¤ß¯}ÃaÂÂÀÉ¡C­Y©p­n¥Î crontab ¤§Ãþªºµ{¦¡¡A¥þ¦Û°Ê¤Æ°õ¦æ¡A³Ì¦n³o¼Ë¡A¥H§K¯}Ãa¸ê®Æ¡C¦]¦¹¡A­Y¼Ð·Ç¿é¤J¤£¬O³s¨ìÁä½L¤W¡A¹w³]¬O fail ¡C

+
+ + +
ask
+ +
+

°Ý©p¸Ó«ç»ò¿ì¡C­Y©p¬O¤â°Ê°õ¦æ¡A³o¼Ë³Ì¤è«K¡C¦]¦¹¡A­Y¼Ð·Ç¿é¤J¬O³s¨ìÁä½L¤W¡A¹w³]¬O ask ¡Cµª®×¬O±q¼Ð·Ç¿é¤JŪªº¡C¦]¬°¼Ð·Ç¿é¤J¥u¦³¤@­Ó¡A­Y©p­n±q¼Ð·Ç¿é¤JŪ°O¿ýÀÉ¡A¤£¯à¶] ask ¼Ò¦¡¡A·|¦Û°Ê°h¦^ fail ¼Ò¦¡¡CÁÙ¦³¡A¦pªG±q¼Ð·Ç¿é¤JŪ¤£¨ìªF¦è¡A¹³ crontab ùؼзǿé¤J³QÃö±¼¤F¡A¤]·|¦Û°Ê°h¦^ fail ¼Ò¦¡¡C

+
+
+
+ + +
-k, --keep ¼Ò¦¡
+ +
+

­ì°O¿ýÀÉ­n«ç»ò³B²z¡C¥Ø«e¦³¤U¦C¼Ò¦¡¡G

+ + +
+
a, all
+ +
+

§¹¥þ«O¯d­ìÀÉ¡C

+
+ + +
r, restart
+ +
+

ÂkÀÉ«á¡A­ì°O¿ýÀÉÂk¹s¡C

+
+ + +
d, delete
+ +
+

ÂkÀÉ«á¡A§R°£­ì°O¿ýÀÉ¡C

+
+ + +
t, this-month
+ +
+

±N¤§«e¤ë¥÷ªº°O¿ýÂkÀÉ¡A«O¯d³o­Ó¤ëªº°O¿ý¡A¯d«Ý¤U­Ó¤ëÂkÀÉ¡C³o¬Oµ¹ crontab ¨C¤ëÂkÀɥΪº¡C¦]¦¹¡A¹w³]¬O this-month ¡C

+
+
+ +
+ + +
-d, --debug
+ +
+

Åã¥Ü¸Ô²Óªº°õ¦æ¹Lµ{¡C

+
+ + +
-q, --quiet
+ +
+

¨S¨Æ¤£­n§n¡C :p

+
+ + +
-h, --help
+ +
+

Åã¥Üµ{¦¡»¡©ú¡C

+
+ + +
-v, --version
+ +
+

Åã¥Üµ{¦¡ª©¥»¡C

+
+
+ + +

ª©ÅvÁn©ú

+ +

ª©Åv©Ò¦³ © 2001-2007 ¨Ìº¿¿ß¡C

+ +

¥»µ{¦¡¬O¦Û¥Ñ³nÅé¡A±z¥i¥H¿í·Ó¦Û¥Ñ³nÅé°òª÷·| (Free Software Foundation) ¥Xª©ªº GNU ³q¥Î¤½¦@³\¥iÃÒ±ø´Ú (GNU General Public License) ²Ä¤Tª©¨Ó­×§ï©M­«·sµo§G³o¤@µ{¦¡¡A©ÎªÌ¦Û¥Ñ¿ï¾Ü¨Ï¥Î¥ô¦ó§ó·sªºª©¥»¡C

+ +

µo§G³o¤@µ{¦¡ªº¥Øªº¬O§Æ±æ¥¦¦³¥Î¡A¦ý¨S¦³¥ô¦ó¾á«O¡C¬Æ¦Ü¨S¦³¾A¦X¯S©w¥Øªº¦ÓÁô§tªº¾á«O¡C§ó¸Ô²Óªº±¡ªp½Ð°Ñ¾\ GNU ³q¥Î¤½¦@³\¥iÃÒ¡C

+ +

±zÀ³¸Ó¤w¸g©Mµ{¦¡¤@°_¦¬¨ì¤@¥÷ GNU ³q¥Î¤½¦@³\¥iÃÒªº°Æ¥»¡C¦pªGÁÙ¨S¦³¡A°Ñ¾\<http://www.gnu.org/licenses/>¡C

+ + +

ª©¥»¬ö¿ý

+ +

½Ð¾\Ū NEWS ÀÉ¡A¬d¬Ýµ{¦¡ªººtÅÜ¡B·s¼Wªº¥\¯à©M­×¸Éªº¿ù»~¡C

+ + +

¤ä´©¨ó§U

+ +

arclog ºô¯¸¬[¦b SourceForge ¡B CPAN »P ®ÈªÙ¨Ìº¿¡C¯Á¨ú³Ì·s¸ê°T¡A½Ð¾rÁ{¡G

+ + + +

¦b SourceForge ¤W¦³¤@­Ó arclog ªº¶l¥ó³q°T ¡C¨Ï¥Î¤Wªº°ÝÃD¡B«Øij©Î¿ù»~¦^³ø¡A½Ð´£¨ì³q°T¤W°Q½×¡C¥¦¬O Mailman ªº¶l¥ó³q°T¡C­Y­n¥[¤J¡A½Ð¨ì arclog ¶l¥ó³q°Tªººô­¶ ¡C©p¤]¥i¥H¼g«H¨ì E-mail «ü¥O«H½c¡A¼ÐÃD¶ñ¤W help ¡A¯Á¨ú E-mail «ü¥O»¡©ú¡C

+ +
+ + +
+ + + + diff --git a/fdl.txt b/fdl.txt new file mode 100644 index 0000000..4a0fe1c --- /dev/null +++ b/fdl.txt @@ -0,0 +1,397 @@ + GNU Free Documentation License + Version 1.2, November 2002 + + + Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + +0. PREAMBLE + +The purpose of this License is to make a manual, textbook, or other +functional and useful document "free" in the sense of freedom: to +assure everyone the effective freedom to copy and redistribute it, +with or without modifying it, either commercially or noncommercially. +Secondarily, this License preserves for the author and publisher a way +to get credit for their work, while not being considered responsible +for modifications made by others. + +This License is a kind of "copyleft", which means that derivative +works of the document must themselves be free in the same sense. It +complements the GNU General Public License, which is a copyleft +license designed for free software. + +We have designed this License in order to use it for manuals for free +software, because free software needs free documentation: a free +program should come with manuals providing the same freedoms that the +software does. But this License is not limited to software manuals; +it can be used for any textual work, regardless of subject matter or +whether it is published as a printed book. We recommend this License +principally for works whose purpose is instruction or reference. + + +1. APPLICABILITY AND DEFINITIONS + +This License applies to any manual or other work, in any medium, that +contains a notice placed by the copyright holder saying it can be +distributed under the terms of this License. Such a notice grants a +world-wide, royalty-free license, unlimited in duration, to use that +work under the conditions stated herein. The "Document", below, +refers to any such manual or work. Any member of the public is a +licensee, and is addressed as "you". You accept the license if you +copy, modify or distribute the work in a way requiring permission +under copyright law. + +A "Modified Version" of the Document means any work containing the +Document or a portion of it, either copied verbatim, or with +modifications and/or translated into another language. + +A "Secondary Section" is a named appendix or a front-matter section of +the Document that deals exclusively with the relationship of the +publishers or authors of the Document to the Document's overall subject +(or to related matters) and contains nothing that could fall directly +within that overall subject. (Thus, if the Document is in part a +textbook of mathematics, a Secondary Section may not explain any +mathematics.) The relationship could be a matter of historical +connection with the subject or with related matters, or of legal, +commercial, philosophical, ethical or political position regarding +them. + +The "Invariant Sections" are certain Secondary Sections whose titles +are designated, as being those of Invariant Sections, in the notice +that says that the Document is released under this License. If a +section does not fit the above definition of Secondary then it is not +allowed to be designated as Invariant. The Document may contain zero +Invariant Sections. If the Document does not identify any Invariant +Sections then there are none. + +The "Cover Texts" are certain short passages of text that are listed, +as Front-Cover Texts or Back-Cover Texts, in the notice that says that +the Document is released under this License. A Front-Cover Text may +be at most 5 words, and a Back-Cover Text may be at most 25 words. + +A "Transparent" copy of the Document means a machine-readable copy, +represented in a format whose specification is available to the +general public, that is suitable for revising the document +straightforwardly with generic text editors or (for images composed of +pixels) generic paint programs or (for drawings) some widely available +drawing editor, and that is suitable for input to text formatters or +for automatic translation to a variety of formats suitable for input +to text formatters. A copy made in an otherwise Transparent file +format whose markup, or absence of markup, has been arranged to thwart +or discourage subsequent modification by readers is not Transparent. +An image format is not Transparent if used for any substantial amount +of text. A copy that is not "Transparent" is called "Opaque". + +Examples of suitable formats for Transparent copies include plain +ASCII without markup, Texinfo input format, LaTeX input format, SGML +or XML using a publicly available DTD, and standard-conforming simple +HTML, PostScript or PDF designed for human modification. Examples of +transparent image formats include PNG, XCF and JPG. Opaque formats +include proprietary formats that can be read and edited only by +proprietary word processors, SGML or XML for which the DTD and/or +processing tools are not generally available, and the +machine-generated HTML, PostScript or PDF produced by some word +processors for output purposes only. + +The "Title Page" means, for a printed book, the title page itself, +plus such following pages as are needed to hold, legibly, the material +this License requires to appear in the title page. For works in +formats which do not have any title page as such, "Title Page" means +the text near the most prominent appearance of the work's title, +preceding the beginning of the body of the text. + +A section "Entitled XYZ" means a named subunit of the Document whose +title either is precisely XYZ or contains XYZ in parentheses following +text that translates XYZ in another language. (Here XYZ stands for a +specific section name mentioned below, such as "Acknowledgements", +"Dedications", "Endorsements", or "History".) To "Preserve the Title" +of such a section when you modify the Document means that it remains a +section "Entitled XYZ" according to this definition. + +The Document may include Warranty Disclaimers next to the notice which +states that this License applies to the Document. These Warranty +Disclaimers are considered to be included by reference in this +License, but only as regards disclaiming warranties: any other +implication that these Warranty Disclaimers may have is void and has +no effect on the meaning of this License. + + +2. VERBATIM COPYING + +You may copy and distribute the Document in any medium, either +commercially or noncommercially, provided that this License, the +copyright notices, and the license notice saying this License applies +to the Document are reproduced in all copies, and that you add no other +conditions whatsoever to those of this License. You may not use +technical measures to obstruct or control the reading or further +copying of the copies you make or distribute. However, you may accept +compensation in exchange for copies. If you distribute a large enough +number of copies you must also follow the conditions in section 3. + +You may also lend copies, under the same conditions stated above, and +you may publicly display copies. + + +3. COPYING IN QUANTITY + +If you publish printed copies (or copies in media that commonly have +printed covers) of the Document, numbering more than 100, and the +Document's license notice requires Cover Texts, you must enclose the +copies in covers that carry, clearly and legibly, all these Cover +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on +the back cover. Both covers must also clearly and legibly identify +you as the publisher of these copies. The front cover must present +the full title with all words of the title equally prominent and +visible. You may add other material on the covers in addition. +Copying with changes limited to the covers, as long as they preserve +the title of the Document and satisfy these conditions, can be treated +as verbatim copying in other respects. + +If the required texts for either cover are too voluminous to fit +legibly, you should put the first ones listed (as many as fit +reasonably) on the actual cover, and continue the rest onto adjacent +pages. + +If you publish or distribute Opaque copies of the Document numbering +more than 100, you must either include a machine-readable Transparent +copy along with each Opaque copy, or state in or with each Opaque copy +a computer-network location from which the general network-using +public has access to download using public-standard network protocols +a complete Transparent copy of the Document, free of added material. +If you use the latter option, you must take reasonably prudent steps, +when you begin distribution of Opaque copies in quantity, to ensure +that this Transparent copy will remain thus accessible at the stated +location until at least one year after the last time you distribute an +Opaque copy (directly or through your agents or retailers) of that +edition to the public. + +It is requested, but not required, that you contact the authors of the +Document well before redistributing any large number of copies, to give +them a chance to provide you with an updated version of the Document. + + +4. MODIFICATIONS + +You may copy and distribute a Modified Version of the Document under +the conditions of sections 2 and 3 above, provided that you release +the Modified Version under precisely this License, with the Modified +Version filling the role of the Document, thus licensing distribution +and modification of the Modified Version to whoever possesses a copy +of it. In addition, you must do these things in the Modified Version: + +A. Use in the Title Page (and on the covers, if any) a title distinct + from that of the Document, and from those of previous versions + (which should, if there were any, be listed in the History section + of the Document). You may use the same title as a previous version + if the original publisher of that version gives permission. +B. List on the Title Page, as authors, one or more persons or entities + responsible for authorship of the modifications in the Modified + Version, together with at least five of the principal authors of the + Document (all of its principal authors, if it has fewer than five), + unless they release you from this requirement. +C. State on the Title page the name of the publisher of the + Modified Version, as the publisher. +D. Preserve all the copyright notices of the Document. +E. Add an appropriate copyright notice for your modifications + adjacent to the other copyright notices. +F. Include, immediately after the copyright notices, a license notice + giving the public permission to use the Modified Version under the + terms of this License, in the form shown in the Addendum below. +G. Preserve in that license notice the full lists of Invariant Sections + and required Cover Texts given in the Document's license notice. +H. Include an unaltered copy of this License. +I. Preserve the section Entitled "History", Preserve its Title, and add + to it an item stating at least the title, year, new authors, and + publisher of the Modified Version as given on the Title Page. If + there is no section Entitled "History" in the Document, create one + stating the title, year, authors, and publisher of the Document as + given on its Title Page, then add an item describing the Modified + Version as stated in the previous sentence. +J. Preserve the network location, if any, given in the Document for + public access to a Transparent copy of the Document, and likewise + the network locations given in the Document for previous versions + it was based on. These may be placed in the "History" section. + You may omit a network location for a work that was published at + least four years before the Document itself, or if the original + publisher of the version it refers to gives permission. +K. For any section Entitled "Acknowledgements" or "Dedications", + Preserve the Title of the section, and preserve in the section all + the substance and tone of each of the contributor acknowledgements + and/or dedications given therein. +L. Preserve all the Invariant Sections of the Document, + unaltered in their text and in their titles. Section numbers + or the equivalent are not considered part of the section titles. +M. Delete any section Entitled "Endorsements". Such a section + may not be included in the Modified Version. +N. Do not retitle any existing section to be Entitled "Endorsements" + or to conflict in title with any Invariant Section. +O. Preserve any Warranty Disclaimers. + +If the Modified Version includes new front-matter sections or +appendices that qualify as Secondary Sections and contain no material +copied from the Document, you may at your option designate some or all +of these sections as invariant. To do this, add their titles to the +list of Invariant Sections in the Modified Version's license notice. +These titles must be distinct from any other section titles. + +You may add a section Entitled "Endorsements", provided it contains +nothing but endorsements of your Modified Version by various +parties--for example, statements of peer review or that the text has +been approved by an organization as the authoritative definition of a +standard. + +You may add a passage of up to five words as a Front-Cover Text, and a +passage of up to 25 words as a Back-Cover Text, to the end of the list +of Cover Texts in the Modified Version. Only one passage of +Front-Cover Text and one of Back-Cover Text may be added by (or +through arrangements made by) any one entity. If the Document already +includes a cover text for the same cover, previously added by you or +by arrangement made by the same entity you are acting on behalf of, +you may not add another; but you may replace the old one, on explicit +permission from the previous publisher that added the old one. + +The author(s) and publisher(s) of the Document do not by this License +give permission to use their names for publicity for or to assert or +imply endorsement of any Modified Version. + + +5. COMBINING DOCUMENTS + +You may combine the Document with other documents released under this +License, under the terms defined in section 4 above for modified +versions, provided that you include in the combination all of the +Invariant Sections of all of the original documents, unmodified, and +list them all as Invariant Sections of your combined work in its +license notice, and that you preserve all their Warranty Disclaimers. + +The combined work need only contain one copy of this License, and +multiple identical Invariant Sections may be replaced with a single +copy. If there are multiple Invariant Sections with the same name but +different contents, make the title of each such section unique by +adding at the end of it, in parentheses, the name of the original +author or publisher of that section if known, or else a unique number. +Make the same adjustment to the section titles in the list of +Invariant Sections in the license notice of the combined work. + +In the combination, you must combine any sections Entitled "History" +in the various original documents, forming one section Entitled +"History"; likewise combine any sections Entitled "Acknowledgements", +and any sections Entitled "Dedications". You must delete all sections +Entitled "Endorsements". + + +6. COLLECTIONS OF DOCUMENTS + +You may make a collection consisting of the Document and other documents +released under this License, and replace the individual copies of this +License in the various documents with a single copy that is included in +the collection, provided that you follow the rules of this License for +verbatim copying of each of the documents in all other respects. + +You may extract a single document from such a collection, and distribute +it individually under this License, provided you insert a copy of this +License into the extracted document, and follow this License in all +other respects regarding verbatim copying of that document. + + +7. AGGREGATION WITH INDEPENDENT WORKS + +A compilation of the Document or its derivatives with other separate +and independent documents or works, in or on a volume of a storage or +distribution medium, is called an "aggregate" if the copyright +resulting from the compilation is not used to limit the legal rights +of the compilation's users beyond what the individual works permit. +When the Document is included in an aggregate, this License does not +apply to the other works in the aggregate which are not themselves +derivative works of the Document. + +If the Cover Text requirement of section 3 is applicable to these +copies of the Document, then if the Document is less than one half of +the entire aggregate, the Document's Cover Texts may be placed on +covers that bracket the Document within the aggregate, or the +electronic equivalent of covers if the Document is in electronic form. +Otherwise they must appear on printed covers that bracket the whole +aggregate. + + +8. TRANSLATION + +Translation is considered a kind of modification, so you may +distribute translations of the Document under the terms of section 4. +Replacing Invariant Sections with translations requires special +permission from their copyright holders, but you may include +translations of some or all Invariant Sections in addition to the +original versions of these Invariant Sections. You may include a +translation of this License, and all the license notices in the +Document, and any Warranty Disclaimers, provided that you also include +the original English version of this License and the original versions +of those notices and disclaimers. In case of a disagreement between +the translation and the original version of this License or a notice +or disclaimer, the original version will prevail. + +If a section in the Document is Entitled "Acknowledgements", +"Dedications", or "History", the requirement (section 4) to Preserve +its Title (section 1) will typically require changing the actual +title. + + +9. TERMINATION + +You may not copy, modify, sublicense, or distribute the Document except +as expressly provided for under this License. Any other attempt to +copy, modify, sublicense or distribute the Document is void, and will +automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + + +10. FUTURE REVISIONS OF THIS LICENSE + +The Free Software Foundation may publish new, revised versions +of the GNU Free Documentation License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. See +http://www.gnu.org/copyleft/. + +Each version of the License is given a distinguishing version number. +If the Document specifies that a particular numbered version of this +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that specified version or +of any later version that has been published (not as a draft) by the +Free Software Foundation. If the Document does not specify a version +number of this License, you may choose any version ever published (not +as a draft) by the Free Software Foundation. + + +ADDENDUM: How to use this License for your documents + +To use this License in a document you have written, include a copy of +the License in the document and put the following copyright and +license notices just after the title page: + + Copyright (c) YEAR YOUR NAME. + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.2 + or any later version published by the Free Software Foundation; + with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. + A copy of the license is included in the section entitled "GNU + Free Documentation License". + +If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, +replace the "with...Texts." line with this: + + with the Invariant Sections being LIST THEIR TITLES, with the + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. + +If you have Invariant Sections without Cover Texts, or some other +combination of the three, merge those two alternatives to suit the +situation. + +If your document contains nontrivial examples of program code, we +recommend releasing these examples in parallel under your choice of +free software license, such as the GNU General Public License, +to permit their use in free software. diff --git a/pgpkey.asc b/pgpkey.asc new file mode 100644 index 0000000..bd75349 --- /dev/null +++ b/pgpkey.asc @@ -0,0 +1,40 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.1 (GNU/Linux) + +mQGiBD0kfGQRBADaGggoSHTZ8P17j92IMMxWPpML0TdvbhzW5iFF7a5th0xCn9od +pHVwc2YxuEulwDz0LJUx2IwwbttftHcJafcH51vk57Qq2+hvNAE1o9a/MWReMIwv +KfBi3Q1bVxWIjVPDbHd+ZUbbo0pozbfrHEaRPQ0qR+/ZgK5+V6WJiLElrwCgsCQy +FGfo72h5p46w7MrW4qSmalkD/RMcVmPkszF5J0N9pWlgcJ/fTYlMKIit3V/W/fru +L4KkUT3d9CMcJSBZrcVlXlDbPeBF8L7vl46NImd4xfnRKLwOuAy67Tld6CbC+UWz +rv6472rGetTTaj7iBH5nR62BQUmaLK6W6Q8vFOrqIBqXEz5iJ+RLYpIxH5M8gOz5 +7b7GBACIZaPaMVzIbTqnysDCgKEQqOyFbpgcGfSH52xH3XXeNrJhuenJFvBbeV8J +RgmKSnn1ZixFHJ261uGu5kOA1CQemNrTgZRaeHDu6mdZALdbxpLXp9DeOC/oTUWa +1O2xmAWcZZo+63s0MciC9zDrRjlNuGcVOiHZZLh9P9vEfoJos7Qu5L6d55Gq6LKT +IChpbWFjYXQpIDxpbWFjYXRAbWFpbC5pbWFjYXQuaWR2LnR3PoheBBMRAgAeBQJC +iLwmAhsDBgsJCAcDAgMVAgMDFgIBAh4BAheAAAoJEIvYLm8wuUtcmnYAnRQCNXWc +vgtk4CiTTBWqGWWZRjViAKCn/F6maM9R5RzuC1L5ER27f0AjbrkEDQQ9JHzZEBAA +owxPPj1TOZKGuav0eKopd8RrwFQ51P0FY85WyTAsCWg/KGcJIXFKwJ/r4U381iQd +z+16+E6oOzTIs/iwnkSKmfWx2M46uXdIa/VkLChZzHpCVDHeVICGE5sbECNS2gYD +CRx/Jl/FnXNaeaI0RZm3i4gf204bvqsPm+epI/BOW4cZmbkqSd4BuG2/i7y/BZzP +NhVseNVe2qhWFxs4Hj5S6y6xYSuuPLC4mZrkA7x1J9tq+wUt6z0mwIdRhEaK5iE5 +PB44XiwGKW02sLt5CQXDW/DbqXlyu6VP90iVjWLg0ftI28dULipw2n6u0DIGIxfL +i4dDf0gcYyqDF++aMWYTlB7a89Vt055dp7NC59VaqltW9DgKnxkiTUMxZ3HtqA67 +rwKtwKY3CQyuIYil31AQy0izi4fIu6MRznLtwHAfaqsB0Nej+kFl1XSUspe3P6ea +YzMs7on0X0KvPDWPo7AMz0Y/ex/XzYwR2+IzijTnaakH5TS7da0LKXb3FTV/PuIR +UgH3P/yOwRyOU4VLWqcyLxBJuMlX1WVz3UdNfHwRfm+jqPktP0qnQ9ZrFk3VEOGv +0hMvCeqj3Vw5CziYCTm3YiDG4OLPpUN3ByF944cUCYKwoGYEUKUf0vXPvUYdshqB +D49RyI0oy2nZstSt+iVefuCyWBYEyqIDu0eRGWY8FRMAAwUQAI/jMOnq6mP7mfbs +qq1ugXtx0r7cKNge0ebB/TA37ZLCo2UTdoxk/AsuGx1MK6kKJh3Zkxz89jb84CXA +jZbYbLOGhFioHCyiqfJwFbR7Abhsoo1NuEAtibJpFUm0oHym/Tjc4Xwht7cf52+8 +USfC918mFzmbPDOuIpkcHjGzXFztgDiMlX7iDrMvX2QOLzhp+g/I/pyAhAcKH8Eo +vcKeYOoQIM7hpP0eTZxgCDdRw9SpodU0/rTL6UzA4iXMcqncspH0OjfT5gxj3cOo +ofhaPxsIoqllZA/V/x7CeykdNE5L5SYv3c0NBnTMe9kV4K8V0JHTyz7N3ipiWJHP +VObvgdrJyA9YYCpgorfE7a1rtmLPfr5evrTuKP+VMEInqvA0mAxzX/HsbtsA+bNn +g6c5WibjO/kDKgfZfHFrPlLPiSSBVn9ygEySdlBuXpb5c7wft/YV0FyVAikbhY3l +3jJYmQ7kBxrtoIH9jK6Ff8rw7qbyBg6fDPoC3gevNdmoVtk5vTcKQTxPKlCeXTtE +JYfKDvX0BDkV8Wdizit03Sp0StpeietlX5vYQDyefp+w5J3k2SrbkEczzGZzXHq/ +5pm36cC0N0rA8ZW7JOpkThjZIJ733Y5DwtzhWqdUubWiCMmC7HfGmpI0OdV6QF8p +kCKXIsJ90Uiep0lEDNQZg4Y96kuUiEYEGBECAAYFAj0kfNoACgkQi9gubzC5S1xO +uACdELzJCBgMJVZ9siHwn48X2rXdQnIAn0yagIZfaIS0CfCamwcYeMfKcQQV +=GeL3 +-----END PGP PUBLIC KEY BLOCK----- diff --git a/t/00-signature.t b/t/00-signature.t new file mode 100755 index 0000000..1cf917c --- /dev/null +++ b/t/00-signature.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use strict; +print "1..1\n"; + +if (!-s 'SIGNATURE') { + print "ok 1 # skip No signature file found\n"; +} +elsif (!eval { require Module::Signature; 1 }) { + print "ok 1 # skip ", + "Next time around, consider install Module::Signature, ", + "so you can verify the integrity of this distribution.\n"; +} +elsif (!eval { require Socket; Socket::inet_aton('pgp.mit.edu') }) { + print "ok 1 # skip Cannot connect to the keyserver\n"; +} +else { + (Module::Signature::verify() == Module::Signature::SIGNATURE_OK()) + or print "not "; + print "ok 1 # Valid signature\n"; +} + +__END__ diff --git a/t/01-exhaust.t b/t/01-exhaust.t new file mode 100755 index 0000000..d866b64 --- /dev/null +++ b/t/01-exhaust.t @@ -0,0 +1,145 @@ +#! /usr/bin/perl -w +# Test all the possible combination of options + +# Copyright (c) 2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use 5.005; +use strict; +use warnings; +use diagnostics; +use Test; + +BEGIN { plan tests => 2160 } + +use File::Basename qw(basename); +use File::Path qw(mkpath rmtree); +use File::Spec::Functions qw(catdir catfile updir); +use FindBin; +use lib $FindBin::Bin; +use _helper; +use vars qw($WORKDIR $arclog $tno); + +$WORKDIR = catdir($FindBin::Bin, "logs"); +$arclog = catfile($FindBin::Bin, updir, "blib", "script", "arclog"); +$tno = 0; + +# 1-2160: All possible option combinations +# Test each log file format +foreach my $fmt (@LOGFMTS) { + # Test each source log file type + foreach my $st (@SRCTYPES) { + # Test each result file type + foreach my $rt (@RESTYPES) { + # Test each keep type + foreach my $kt (@KEEPTYPES) { + # Test each override type + foreach my $ot (@OVERTYPES) { + $_ = eval { + return if $$st{"skip"} || $$rt{"skip"}; + my ($title, $cmd, $retno, $out, $err, $vardump, $logfile); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($fs, $cs, %cem, @mle, $mt, %cof); + rmtree $WORKDIR; + mkpath $WORKDIR; + $title = join ", ", ($$fmt{"title"}, $$st{"title"}, + $$rt{"title"}, $$kt{"title"}, $$ot{"title"}); + $logfile = randword; + $fs = catfile($WORKDIR, $logfile . $$st{"suf"}); + ($cs, $vardump, %cem) = &{$$fmt{"sub"}}($fs); + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + @mle = sort keys %cem; + $mt = pop @mle if $$kt{"tm"}; + if ($$ot{"mkex"}) { + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$logfile.%s" . $$rt{"suf"}, @mle; + } else { + %cof = map { "$logfile.$_" . $$rt{"suf"} => "" } + @mle; + } + @fle = qw(); + push @fle, basename($fs) if !$$kt{"del"}; + push @fle, "$logfile.vardump"; + if ($$ot{"ok"}) { + push @fle, map "$logfile.$_" . $$rt{"suf"}, @mle; + } else { + push @fle, "$logfile.tmp-arclog" if $$kt{"tmp"}; + push @fle, grep $cof{$_} ne "", keys %cof; + } + prsrvsrc $WORKDIR; + if (!$$kt{"stdin"}) { + @_ = ($arclog, qw(-d -d -d), @{$$kt{"opts"}}, + @{$$ot{"opts"}}, @{$$rt{"opts"}}, $fs); + $cmd = join " ", @_; + ($retno, $out, $err) = runcmd "", @_; + } else { + @_ = ($arclog, qw(-d -d -d), @{$$kt{"opts"}}, + @{$$ot{"opts"}}, @{$$rt{"opts"}}, "-", + catfile($WORKDIR, $logfile)); + $cmd = join(" ", @_) . " < " . $fs; + ($retno, $out, $err) = runcmd frread $fs, @_; + } + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + if (!$$kt{"del"}) { + $fr = $fs; + $frb = basename($fr); + $cef{$frb} = !$$kt{"tmp"}? $cs: + !$$ot{"ok"}? "": + $$kt{"tm"}? $cem{$mt}: ""; + $tef{$frb} = $$st{"type"}; + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + if (!$$ot{"ok"} && $$kt{"tmp"}) { + $frb = "$logfile.tmp-arclog"; + $fr = catfile($WORKDIR, $frb); + ($cef{$frb}, $tef{$frb}) = ($cs, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + $frb = "$logfile.vardump"; + $fr = catfile($WORKDIR, $frb); + ($cef{$frb}, $tef{$frb}) = ($vardump, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + foreach my $m (@mle) { + $frb = "$logfile.$m" . $$rt{"suf"}; + $fr = catfile($WORKDIR, $frb); + $cef{$frb} = &{$$ot{"ce"}}($cof{$frb}, $cem{$m}); + $tef{$frb} = $$rt{"type"}; + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" + unless $$ot{"ok"}? $retno == 0: $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nVariables: $vardump\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nVariables: $vardump\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr} + || ($tef{$fr} eq TYPE_BZIP2 && -z catfile($WORKDIR, $fr)); + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nVariables: $vardump\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; + }; + skip($$st{"skip"} || $$rt{"skip"}, $_, 1, $@); + cleanup $_ || $$st{"skip"} || $$rt{"skip"}, $WORKDIR, ++$tno; + die unless $_ || $$st{"skip"} || $$rt{"skip"}; + } + } + } + } +} diff --git a/t/02-several.t b/t/02-several.t new file mode 100755 index 0000000..317db03 --- /dev/null +++ b/t/02-several.t @@ -0,0 +1,266 @@ +#! /usr/bin/perl -w +# Test archiving several log files at once + +# Copyright (c) 2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use 5.005; +use strict; +use warnings; +use diagnostics; +use Test; + +BEGIN { plan tests => 16 } + +use File::Basename qw(basename); +use File::Path qw(mkpath rmtree); +use File::Spec::Functions qw(catdir catfile updir); +use FindBin; +use lib $FindBin::Bin; +use _helper; +use vars qw($WORKDIR $arclog $tno); + +$WORKDIR = catdir($FindBin::Bin, "logs"); +$arclog = catfile($FindBin::Bin, updir, "blib", "script", "arclog"); +$tno = 0; + +# 1-16: Archiving several log files at once +foreach my $rt (@RESTYPES) { + my $skip; + $skip = 0; + # 1: Source log files listed as the arguments + $_ = eval { + if ( ($$rt{"type"} eq TYPE_GZIP && nogzip) + || ($$rt{"type"} eq TYPE_BZIP2 && nobzip2)) { + $skip = 1; + return; + } + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $mt); + my (@st, $fmt); + rmtree $WORKDIR; + mkpath $WORKDIR; + $fmt = $LOGFMTS[int rand @LOGFMTS]; + $title = join ", ", "several log files", "all listed as arguments", + $$fmt{"title"}, $$rt{"title"}; + # (2-4 times available compression) log files + $_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2); + $num = $_ + int rand $_; + %_ = qw(); + # At least 2 files for each available compression + foreach my $st (@SRCTYPES) { + next if ($$st{"type"} eq TYPE_GZIP && nogzip) + || ($$st{"type"} eq TYPE_BZIP2 && nobzip2); + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + } + # Set random compression on the rest files + foreach (grep !exists $_{$_}, (0...$num-1)) { + do { + $_{$_} = $SRCTYPES[int rand @SRCTYPES]; + } until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip) + && !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2); + } + @st = map $_{$_}, (0...$num-1); + @fs = qw(); + @cs = qw(); + @cem = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + $logfile .= ${$st[$k]}{"suf"}; + push @fs, catfile($WORKDIR, $logfile); + ($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]); + push @cs, $cs; + push @cem, {%_}; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + %_ = qw(); + %_ = (%_, map { $_ => 1 } keys %$_) foreach @cem; + @mle = sort keys %_; + $mt = pop @mle; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle; + push @fle, map "$oprfb.$_" . $$rt{"suf"}, @mle; + prsrvsrc $WORKDIR; + @_ = ($arclog, qw(-d -d -d -o a), @{$$rt{"opts"}}, @fs, $opref); + $cmd = join(" ", @_); + ($retno, $out, $err) = runcmd "", @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = (${$cem[$k]}{$mt}, ${$st[$k]}{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $fr = $fs[$k] . ".vardump"; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + foreach my $m (@mle) { + $fr = "$opref.$m" . $$rt{"suf"}; + $frb = basename($fr); + $cef{$frb} = $cof{$frb} + . join "", map(exists $$_{$m}? $$_{$m}: "", @cem); + $tef{$frb} = $$rt{"type"}; + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno == 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; + }; + skip($skip, $_, 1, $@); + cleanup $_ || $skip, $WORKDIR, ++$tno; + + # 2-4: One of the source log files is read from STDIN + # The file type at STDIN + foreach my $ststdin (@SRCTYPES) { + $skip = 0; + $_ = eval { + if ( ($$rt{"type"} eq TYPE_GZIP && nogzip) + || ($$rt{"type"} eq TYPE_BZIP2 && nobzip2) + || ($$ststdin{"type"} eq TYPE_GZIP && nogzip) + || ($$ststdin{"type"} eq TYPE_BZIP2 && nobzip2)) { + $skip = 1; + return; + } + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $stdin); + my (@st, $fmt); + rmtree $WORKDIR; + mkpath $WORKDIR; + $fmt = $LOGFMTS[int rand @LOGFMTS]; + $title = join ", ", "several log files", "one read from STDIN", + "STDIN " . $$ststdin{"title"}, $$rt{"title"}; + # (2-4 times available compression) log files + $_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2); + $num = $_ + int rand $_; + %_ = qw(); + # At least 2 files for each available compression + foreach my $st (@SRCTYPES) { + next if ($$st{"type"} eq TYPE_GZIP && nogzip) + || ($$st{"type"} eq TYPE_BZIP2 && nobzip2); + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + } + # Set random compression on the rest files + foreach (grep !exists $_{$_}, (0...$num-1)) { + do { + $_{$_} = $SRCTYPES[int rand @SRCTYPES]; + } until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip) + && !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2); + } + # Choose the STDIN from the matching compression + @_ = grep ${$_{$_}}{"type"} eq $$ststdin{"type"}, (0...$num-1); + $stdin = $_[int rand @_]; + @st = map $_{$_}, (0...$num-1); + @fs = qw(); + @cs = qw(); + @cem = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + $logfile .= ${$st[$k]}{"suf"}; + push @fs, catfile($WORKDIR, $logfile); + ($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]); + push @cs, $cs; + push @cem, {%_}; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + %_ = qw(); + %_ = (%_, map { $_ => 1 } keys %$_) foreach @cem; + @mle = sort keys %_; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle; + push @fle, map "$oprfb.$_" . $$rt{"suf"}, @mle; + prsrvsrc $WORKDIR; + @_ = @fs; + $_[$stdin] = "-"; + @_ = ($arclog, qw(-d -d -d -k a -o a), @{$$rt{"opts"}}, @_, $opref); + $cmd = join(" ", @_) . " < " . $fs[$stdin]; + ($retno, $out, $err) = runcmd frread $fs[$stdin], @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $fr = $fs[$k] . ".vardump"; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + foreach my $m (@mle) { + $fr = "$opref.$m" . $$rt{"suf"}; + $frb = basename($fr); + $cef{$frb} = $cof{$frb} + . join "", map(exists $$_{$m}? $$_{$m}: "", @cem); + $tef{$frb} = $$rt{"type"}; + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno == 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; + }; + skip($skip, $_, 1, $@); + cleanup $_ || $skip, $WORKDIR, ++$tno; + } +} diff --git a/t/03-fallback.t b/t/03-fallback.t new file mode 100755 index 0000000..07ddec3 --- /dev/null +++ b/t/03-fallback.t @@ -0,0 +1,256 @@ +#! /usr/bin/perl -w +# Test fallback behavior + +# Copyright (c) 2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use 5.005; +use strict; +use warnings; +use diagnostics; +use Test; + +BEGIN { plan tests => 5 } + +use File::Basename qw(basename); +use File::Path qw(mkpath rmtree); +use File::Spec::Functions qw(catdir catfile updir); +use FindBin; +use lib $FindBin::Bin; +use _helper; +use vars qw($WORKDIR $arclog $tno); + +$WORKDIR = catdir($FindBin::Bin, "logs"); +$arclog = catfile($FindBin::Bin, updir, "blib", "script", "arclog"); +$tno = 0; + +# 1-4: STDIN keep fall back +foreach my $kt (@KEEPTYPES) { + next if $$kt{"stdin"} || $$kt{"title"} eq "keep all"; + $_ = eval { + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $stdin); + my (@st, $fmt, $rt); + rmtree $WORKDIR; + mkpath $WORKDIR; + $fmt = $LOGFMTS[int rand @LOGFMTS]; + # A random available compression + do { + $rt = $RESTYPES[int rand @RESTYPES]; + } until !($$rt{"type"} eq TYPE_GZIP && nogzip) + && !($$rt{"type"} eq TYPE_BZIP2 && nobzip2); + $title = join ", ", "STDIN keep fall back", $$kt{"title"}, + $$fmt{"title"}, $$rt{"title"}; + # (2-4 times available compression) log files + $_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2); + $num = $_ + int rand $_; + $stdin = int rand $num; + %_ = qw(); + # At least 2 files for each available compression + foreach my $st (@SRCTYPES) { + next if ($$st{"type"} eq TYPE_GZIP && nogzip) + || ($$st{"type"} eq TYPE_BZIP2 && nobzip2); + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + } + # Set random compression on the rest files + foreach (grep !exists $_{$_}, (0...$num-1)) { + do { + $_{$_} = $SRCTYPES[int rand @SRCTYPES]; + } until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip) + && !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2); + } + @st = map $_{$_}, (0...$num-1); + @fs = qw(); + @cs = qw(); + @cem = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + $logfile .= ${$st[$k]}{"suf"}; + push @fs, catfile($WORKDIR, $logfile); + ($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]); + push @cs, $cs; + push @cem, {%_}; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + %_ = qw(); + %_ = (%_, map { $_ => 1 } keys %$_) foreach @cem; + @mle = sort keys %_; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle; + push @fle, map "$oprfb.$_" . $$rt{"suf"}, @mle; + prsrvsrc $WORKDIR; + @_ = @fs; + $_[$stdin] = "-"; + @_ = ($arclog, qw(-d -d -d -o a), @{$$kt{"opts"}}, @{$$rt{"opts"}}, @_, $opref); + $cmd = join(" ", @_) . " < " . $fs[$stdin]; + ($retno, $out, $err) = runcmd frread $fs[$stdin], @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $fr = $fs[$k] . ".vardump"; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + foreach my $m (@mle) { + $fr = "$opref.$m" . $$rt{"suf"}; + $frb = basename($fr); + $cef{$frb} = $cof{$frb} + . join "", map(exists $$_{$m}? $$_{$m}: "", @cem); + $tef{$frb} = $$rt{"type"}; + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno == 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; + }; + ok($_, 1, $@); + cleanup $_, $WORKDIR, ++$tno; +} + +# 5: STDIN override ask fall back +$_ = eval { + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $stdin); + my (@st, $fmt, $rt); + rmtree $WORKDIR; + mkpath $WORKDIR; + $fmt = $LOGFMTS[int rand @LOGFMTS]; + # A random available compression + do { + $rt = $RESTYPES[int rand @RESTYPES]; + } until !($$rt{"type"} eq TYPE_GZIP && nogzip) + && !($$rt{"type"} eq TYPE_BZIP2 && nobzip2); + $title = join ", ", "STDIN override ask fall back", + $$fmt{"title"}, $$rt{"title"}; + # (2-4 times available compression) log files + $_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2); + $num = $_ + int rand $_; + $stdin = int rand $num; + %_ = qw(); + # At least 2 files for each available compression + foreach my $st (@SRCTYPES) { + next if ($$st{"type"} eq TYPE_GZIP && nogzip) + || ($$st{"type"} eq TYPE_BZIP2 && nobzip2); + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + } + # Set random compression on the rest files + foreach (grep !exists $_{$_}, (0...$num-1)) { + do { + $_{$_} = $SRCTYPES[int rand @SRCTYPES]; + } until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip) + && !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2); + } + @st = map $_{$_}, (0...$num-1); + @fs = qw(); + @cs = qw(); + @cem = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + $logfile .= ${$st[$k]}{"suf"}; + push @fs, catfile($WORKDIR, $logfile); + ($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]); + push @cs, $cs; + push @cem, {%_}; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + %_ = qw(); + %_ = (%_, map { $_ => 1 } keys %$_) foreach @cem; + @mle = sort keys %_; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle; + push @fle, grep $cof{$_} ne "", keys %cof; + prsrvsrc $WORKDIR; + @_ = @fs; + $_[$stdin] = "-"; + @_ = ($arclog, qw(-d -d -d -o ask), @{$$rt{"opts"}}, @_, $opref); + $cmd = join(" ", @_) . " < " . $fs[$stdin]; + ($retno, $out, $err) = runcmd frread $fs[$stdin], @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $fr = $fs[$k] . ".vardump"; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + foreach my $m (@mle) { + $fr = "$opref.$m" . $$rt{"suf"}; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cof{$frb}, $$rt{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; +}; +ok($_, 1, $@); +cleanup $_, $WORKDIR, ++$tno; diff --git a/t/04-errors.t b/t/04-errors.t new file mode 100755 index 0000000..88d2589 --- /dev/null +++ b/t/04-errors.t @@ -0,0 +1,308 @@ +#! /usr/bin/perl -w +# Test the errors that should be captured. + +# Copyright (c) 2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use 5.005; +use strict; +use warnings; +use diagnostics; +use Test; + +BEGIN { plan tests => 23 } + +use File::Basename qw(basename); +use File::Path qw(mkpath rmtree); +use File::Spec::Functions qw(catdir catfile updir); +use FindBin; +use lib $FindBin::Bin; +use _helper; +use vars qw($WORKDIR $arclog $tno); + +$WORKDIR = catdir($FindBin::Bin, "logs"); +$arclog = catfile($FindBin::Bin, updir, "blib", "script", "arclog"); +$tno = 0; + +# 1: STDIN alone +$_ = eval { + my ($title, $cmd, $retno, $out, $err, $vardump, $logfile); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($fs, $cs, %cem); + rmtree $WORKDIR; + mkpath $WORKDIR; + $title = "STDIN alone"; + $logfile = randword; + $fs = catfile($WORKDIR, $logfile); + ($cs, $vardump, %cem) = mkrndlog_apache $fs; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + @fle = qw(); + push @fle, basename($fs); + push @fle, "$logfile.vardump"; + prsrvsrc $WORKDIR; + @_ = ($arclog, qw(-d -d -d -c n), "-"); + $cmd = join(" ", @_) . " < " . $fs; + ($retno, $out, $err) = runcmd frread $fs, @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + $fr = $fs; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $frb = "$logfile.vardump"; + $fr = catfile($WORKDIR, $frb); + ($cef{$frb}, $tef{$frb}) = ($vardump, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + die "$title\n$cmd\n$out$err" unless $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; +}; +ok($_, 1, $@); +cleanup $_, $WORKDIR, ++$tno; + +# 2: STDOUT as output prefix +$_ = eval { + my ($title, $cmd, $retno, $out, $err, $vardump, $logfile); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($fs, $cs, %cem); + rmtree $WORKDIR; + mkpath $WORKDIR; + $title = "STDOUT as output prefix"; + $logfile = randword; + $fs = catfile($WORKDIR, $logfile); + ($cs, $vardump, %cem) = mkrndlog_apache $fs; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + @fle = qw(); + push @fle, basename($fs); + push @fle, "$logfile.vardump"; + prsrvsrc $WORKDIR; + @_ = ($arclog, qw(-d -d -d -c n), $logfile, "-"); + $cmd = join " ", @_; + ($retno, $out, $err) = runcmd "", @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + $fr = $fs; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $frb = "$logfile.vardump"; + $fr = catfile($WORKDIR, $frb); + ($cef{$frb}, $tef{$frb}) = ($vardump, TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + die "$title\n$cmd\n$out$err" unless $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; +}; +ok($_, 1, $@); +cleanup $_, $WORKDIR, ++$tno; + +# 3: A same log file is specified more than once +$_ = eval { + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, @fs, @cs, @cem, @mle, %cof, $opref, $oprfb, $mt); + my (@st, $fmt, $rt, $dup); + rmtree $WORKDIR; + mkpath $WORKDIR; + $fmt = $LOGFMTS[int rand @LOGFMTS]; + $rt = $RESTYPES[int rand @RESTYPES]; + $title = join ",", "A same log file is specified more than once", + $$fmt{"title"}, $$rt{"title"}; + # (2-4 times available compression) log files + $_ = 2 + (nogzip? 0: 2) + (nobzip2? 0: 2); + $num = $_ + int rand $_; + %_ = qw(); + # At least 2 files for each available compression + foreach my $st (@SRCTYPES) { + next if ($$st{"type"} eq TYPE_GZIP && nogzip) + || ($$st{"type"} eq TYPE_BZIP2 && nobzip2); + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + @_ = grep !exists $_{$_}, (0...$num-1); + $_{$_[int rand @_]} = $st; + } + # Set random compression on the rest files + foreach (grep !exists $_{$_}, (0...$num-1)) { + do { + $_{$_} = $SRCTYPES[int rand @SRCTYPES]; + } until !(${$_{$_}}{"type"} eq TYPE_GZIP && nogzip) + && !(${$_{$_}}{"type"} eq TYPE_BZIP2 && nobzip2); + } + @st = map $_{$_}, (0...$num-1); + @fs = qw(); + @cs = qw(); + @cem = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + $logfile .= ${$st[$k]}{"suf"}; + push @fs, catfile($WORKDIR, $logfile); + ($cs, $vardump, %_) = &{$$fmt{"sub"}}($fs[$k]); + push @cs, $cs; + push @cem, {%_}; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + %_ = qw(); + %_ = (%_, map { $_ => 1 } keys %$_) foreach @cem; + @mle = sort keys %_; + $mt = pop @mle; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + %cof = mkrndlog_existing $$fmt{"sub"}, + $WORKDIR, "$oprfb.%s" . $$rt{"suf"}, @mle; + push @fle, map basename($_), grep $cof{$_} ne "", keys %cof; + prsrvsrc $WORKDIR; + $dup = $fs[int rand @fs]; + $_ = int rand(@fs + 1); + @_ = (@fs[0...$_-1], $dup, @fs[$_...$#fs]); + @_ = ($arclog, qw(-d -d -d -o a), @{$$rt{"opts"}}, @_, $opref); + $cmd = join(" ", @_); + ($retno, $out, $err) = runcmd "", @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs[$k], ${$st[$k]}{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $fr = $fs[$k] . ".vardump"; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + foreach my $m (@mle) { + $fr = "$opref.$m" . $$rt{"suf"}; + $frb = basename($fr); + next if $cof{$frb} eq ""; + ($cef{$frb}, $tef{$frb}) = ($cof{$frb}, $$rt{"type"}); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; +}; +ok($_, 1, $@); +cleanup $_, $WORKDIR, ++$tno; + +# 4-23: Mixing different formats +for (my $i = 0; $i < @LOGFMTS; $i++) { + for (my $j = 0; $j < @LOGFMTS; $j++) { + next if $i == $j; + $_ = eval { + my ($title, $cmd, $retno, $out, $err, @vardump, %logfiles); + my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf); + my ($num, $swan, @fs, @cs, $opref, $oprfb); + rmtree $WORKDIR; + mkpath $WORKDIR; + $title = join ",", "Mixing formats", ${$LOGFMTS[$i]}{"title"}, + ${$LOGFMTS[$j]}{"title"}; + # 3-5 log files + $num = 3 + int rand 3; + $swan = 1 + int rand($num - 1); + @fs = qw(); + @cs = qw(); + @vardump = qw(); + @fle = qw(); + %logfiles = qw(); + for (my $k = 0; $k < $num; $k++) { + my ($logfile, $cs, $vardump); + do { $logfile = randword } until !exists $logfiles{$logfile}; + $logfiles{$logfile} = 1; + push @fs, catfile($WORKDIR, $logfile); + if ($k != $swan) { + ($cs, $vardump, %_) = &{${$LOGFMTS[$i]}{"sub"}}($fs[$k]); + } else { + ($cs, $vardump, %_) = &{${$LOGFMTS[$j]}{"sub"}}($fs[$k]); + } + push @cs, $cs; + push @fle, $logfile; + push @vardump, $vardump; + frwrite(catfile($WORKDIR, "$logfile.vardump"), $vardump); + push @fle, "$logfile.vardump"; + } + prsrvsrc $WORKDIR; + do { $oprfb = randword } until !exists $logfiles{$oprfb}; + $opref = catfile($WORKDIR, $oprfb); + @_ = ($arclog, qw(-d -d -d -c n), @fs, $opref); + $cmd = join " ", @_; + ($retno, $out, $err) = runcmd "", @_; + ($fle, $flr) = (join(" ", sort @fle), flist $WORKDIR); + %cef = qw(); # Expected content by file + %tef = qw(); # Expected file type by file + %crf = qw(); # Resulted content by file + %trf = qw(); # Resulted file type by file + for (my $k = 0; $k < $num; $k++) { + $fr = $fs[$k]; + $frb = basename($fr); + ($cef{$frb}, $tef{$frb}) = ($cs[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + $frb = "$frb.vardump"; + $fr = catfile($WORKDIR, $frb); + ($cef{$frb}, $tef{$frb}) = ($vardump[$k], TYPE_PLAIN); + ($crf{$frb}, $trf{$frb}) = (fread $fr, ftype $fr); + } + die "$title\n$cmd\n$out$err" unless $retno != 0; + die "$title\n$cmd\nresult files incorrect.\nGot: $flr\nExpected: $fle\nOutput:\n$out$err" + unless $flr eq $fle; + foreach $fr (@fle) { + die "$title\n$cmd\n$fr: result type incorrect.\nGot: $trf{$fr}\nExpected: $tef{$fr}\nOutput:\n$out$err" + unless nofile || $trf{$fr} eq $tef{$fr}; + die "$title\n$cmd\n$fr: result incorrect.\nGot:\n$crf{$fr}\nExpected:\n$cef{$fr}\nOutput:\n$out$err" + unless $crf{$fr} eq $cef{$fr}; + } + 1; + }; + ok($_, 1, $@); + cleanup $_, $WORKDIR, ++$tno; + die unless $_; + } +} diff --git a/t/99-pod.t b/t/99-pod.t new file mode 100755 index 0000000..9622b2f --- /dev/null +++ b/t/99-pod.t @@ -0,0 +1,5 @@ +#!/usr/bin/perl +use Test::More; +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok(); diff --git a/t/_helper.pm b/t/_helper.pm new file mode 100644 index 0000000..a2c59a2 --- /dev/null +++ b/t/_helper.pm @@ -0,0 +1,1178 @@ +# _helper.pm - A simple test suite helper + +# Copyright (c) 2007 imacat +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +package _helper; +use 5.005; +use strict; +use warnings; +use base qw(Exporter); +use vars qw($VERSION @EXPORT); +$VERSION = "0.01"; +@EXPORT = qw(); +push @EXPORT, qw(fread frread fwrite frwrite); +push @EXPORT, qw(runcmd whereis ftype flist prsrvsrc cleanup); +push @EXPORT, qw(nofile nogzip nobzip2); +push @EXPORT, qw(mkrndlog_existing); +push @EXPORT, qw(mkrndlog_apache mkrndlog_syslog); +push @EXPORT, qw(mkrndlog_ntp mkrndlog_apachessl mkrndlog_modfiso); +push @EXPORT, qw(randword); +push @EXPORT, qw(TYPE_PLAIN TYPE_GZIP TYPE_BZIP2); +push @EXPORT, qw(@LOGFMTS @SRCTYPES @RESTYPES @KEEPTYPES @OVERTYPES); +# Prototype declaration +sub thisfile(); +sub fread($); +sub frread($); +sub fwrite($$); +sub frwrite($$); +sub runcmd($@); +sub whereis($); +sub ftype($); +sub flist($); +sub prsrvsrc($); +sub cleanup($$$); +sub nofile(); +sub nogzip(); +sub nobzip2(); +sub mkrndlog_existing($$$@); +sub mkrndlog_apache($;$); +sub mkrndlog_syslog($;$); +sub mkrndlog_ntp($;$); +sub mkrndlog_apachessl($;$); +sub mkrndlog_modfiso($;$); +sub monrng_one($); +sub monrng_rand(); +sub split_months(\@); +sub insert_malformed(\@); +sub randword(); +sub randip(); +sub randdomain(); + +use Data::Dumper; +use ExtUtils::MakeMaker qw(); +use Fcntl qw(:seek); +use File::Basename qw(basename); +use File::Copy qw(copy); +use File::Path qw(mkpath rmtree); +use File::Spec::Functions qw(splitdir catdir catfile path); +use File::Temp qw(tempfile); +use Time::Local qw(timelocal); +$Data::Dumper::Indent = 1; + +use vars qw(%WHEREIS $NOFILE $NOGZIP $NOBZIP2); +%WHEREIS = qw(); +undef $NOFILE; +undef $NOGZIP; +undef $NOBZIP2; + +use constant TYPE_PLAIN => "text/plain"; +use constant TYPE_GZIP => "application/x-gzip"; +use constant TYPE_BZIP2 => "application/x-bzip2"; + +use vars qw(@LOGFMTS @SRCTYPES @RESTYPES @KEEPTYPES @OVERTYPES); +# All the log format information +@LOGFMTS = ( { "title" => "Apache acecss log", + "sub" => \&mkrndlog_apache, }, + { "title" => "Syslog", + "sub" => \&mkrndlog_syslog, }, + { "title" => "NTP", + "sub" => \&mkrndlog_ntp, }, + { "title" => "Apache SSL engine log", + "sub" => \&mkrndlog_apachessl, }, + { "title" => "modified ISO 8601 date/time", + "sub" => \&mkrndlog_modfiso, }, ); +# All the source type information +@SRCTYPES = ( { "title" => "plain text source", + "type" => TYPE_PLAIN, + "suf" => "", + "skip" => 0, }, + { "title" => "gzip source", + "type" => TYPE_GZIP, + "suf" => ".gz", + "skip" => nogzip, }, + { "title" => "bzip2 source", + "type" => TYPE_BZIP2, + "suf" => ".bz2", + "skip" => nobzip2, }, ); +# All the result type information +@RESTYPES = ( { "title" => "default compress", + "type" => TYPE_GZIP, + "suf" => ".gz", + "skip" => nogzip, + "opts" => [], }, + { "title" => "gzip compress", + "type" => TYPE_GZIP, + "suf" => ".gz", + "skip" => nogzip, + "opts" => [qw(-c g)], }, + { "title" => "bzip2 compress", + "type" => TYPE_BZIP2, + "suf" => ".bz2", + "skip" => nobzip2, + "opts" => [qw(-c b)], }, + { "title" => "no compress", + "type" => TYPE_PLAIN, + "suf" => "", + "skip" => 0, + "opts" => [qw(-c n)], }, ); +# All the keep type information +@KEEPTYPES = ( { "title" => "keep default", + "opts" => [], + "tm" => 1, + "del" => 0, + "tmp" => 1, + "stdin" => 0, }, + { "title" => "keep all", + "opts" => [qw(-k a)], + "tm" => 0, + "del" => 0, + "tmp" => 0, + "stdin" => 0, }, + { "title" => "keep delete", + "opts" => [qw(-k d)], + "tm" => 0, + "del" => 1, + "tmp" => 1, + "stdin" => 0, }, + { "title" => "keep restart", + "opts" => [qw(-k r)], + "tm" => 0, + "del" => 0, + "tmp" => 1, + "stdin" => 0, }, + { "title" => "keep this month", + "opts" => [qw(-k t)], + "tm" => 1, + "del" => 0, + "tmp" => 1, + "stdin" => 0, }, + { "title" => "keep STDIN", + "opts" => [], + "tm" => 0, + "del" => 0, + "tmp" => 0, + "stdin" => 1, }, ); +# All the override type information +@OVERTYPES = ( { "title" => "override no existing", + "opts" => [], + "mkex" => 0, + "ok" => 1, + "ce" => sub { $_[1]; }, }, + { "title" => "override default", + "opts" => [], + "mkex" => 1, + "ok" => 0, + "ce" => sub { $_[0]; }, }, + { "title" => "override overwrite", + "opts" => [qw(-o o)], + "mkex" => 1, + "ok" => 1, + "ce" => sub { $_[1]; }, }, + { "title" => "override append", + "opts" => [qw(-o a)], + "mkex" => 1, + "ok" => 1, + "ce" => sub { $_[0] . $_[1]; }, }, + { "title" => "override ignore", + "opts" => [qw(-o i)], + "mkex" => 1, + "ok" => 1, + "ce" => sub { $_[0] || $_[1]; }, }, + { "title" => "override fail", + "opts" => [qw(-o f)], + "mkex" => 1, + "ok" => 0, + "ce" => sub { $_[0]; }, }, ); + +# thisfile: Return the name of this file +sub thisfile() { basename($0); } + +# fread: A simple reader to read a log file in any supported format +sub fread($) { + local ($_, %_); + my ($file, $content); + $file = $_[0]; + + # non-existing file + return undef if !-e $file; + + # a gzip compressed file + if ($file =~ /\.gz$/) { + # Compress::Zlib + if (eval { require Compress::Zlib; + import Compress::Zlib qw(gzopen); + 1; }) { + my ($FH, $gz); + $content = ""; + open $FH, $file or die thisfile . ": $file: $!"; + $gz = gzopen($FH, "rb") or die thisfile . ": $file: $!"; + while (1) { + ($gz->gzread($_, 10240) != -1) + or die thisfile . ": $file: " . $gz->gzerror; + $content .= $_; + last if length $_ < 10240; + } + $gz->gzclose and die thisfile . ": $file: " . $gz->gzerror; + return $content; + + # gzip executable + } else { + my ($PH, $CMD); + $CMD = whereis "gzip"; + $CMD = "\"$CMD\" -cd \"$file\""; + open $PH, "$CMD |" or die thisfile . ": $CMD: $!"; + $content = join "", <$PH>; + close $PH or die thisfile . ": $CMD: $!"; + return $content; + } + + # a bzip compressed file + } elsif ($file =~ /\.bz2$/) { + # Compress::Bzip2 + if (eval { require Compress::Bzip2; + import Compress::Bzip2 2.00; + import Compress::Bzip2 qw(bzopen); + 1; }) { + my ($FH, $bz); + $content = ""; + open $FH, $file or die thisfile . ": $file: $!"; + $bz = bzopen($FH, "rb") or die thisfile . ": $file: $!"; + while (1) { + ($bz->bzread($_, 10240) != -1) + or die thisfile . ": $file: " . $bz->bzerror; + $content .= $_; + last if length $_ < 10240; + } + $bz->bzclose and die thisfile . ": $file: " . $bz->bzerror; + return $content; + + # bzip2 executable + } else { + my ($PH, $CMD); + $CMD = whereis "bzip2"; + $CMD = "bzip2 -cd \"$file\""; + open $PH, "$CMD |" or die thisfile . ": $CMD: $!"; + $content = join "", <$PH>; + close $PH or die thisfile . ": $CMD: $!"; + return $content; + } + + # a plain text file + } else { + my $FH; + open $FH, $file or die thisfile . ": $file: $!"; + $content = join "", <$FH>; + close $FH or die thisfile . ": $file: $!"; + return $content; + } +} + +# frread: A raw file reader +sub frread($) { + local ($_, %_); + my ($file, $content, $FH, $size); + $file = $_[0]; + + # non-existing file + return undef if !-e $file; + + $size = (stat $file)[7]; + open $FH, $file or die thisfile . ": $file: $!"; + binmode $FH or die thisfile . ": $file: $!"; + (read($FH, $content, $size) == $size) + or die thisfile . ": $file: $!"; + close $FH or die thisfile . ": $file: $!"; + return $content; +} + +# fwrite: A simple writer to write a log file in any supported format +sub fwrite($$) { + local ($_, %_); + my ($file, $content); + ($file, $content) = @_; + + # a gzip compressed file + if ($file =~ /\.gz$/) { + # Compress::Zlib + if (eval { require Compress::Zlib; + import Compress::Zlib qw(gzopen); + 1; }) { + my ($FH, $gz); + open $FH, ">$file" or die thisfile . ": $file: $!"; + $gz = gzopen($FH, "wb9") or die thisfile . ": $file: $!"; + ($gz->gzwrite($content) == length $content) + or die thisfile . ": $file: " . $gz->gzerror; + $gz->gzclose and die thisfile . ": $file: " . $gz->gzerror; + return; + + # gzip executable + } else { + my ($PH, $CMD); + $CMD = whereis "gzip"; + $CMD = "\"$CMD\" -c9f > \"$file\""; + open $PH, "| $CMD" or die thisfile . ": $CMD: $!"; + print $PH $content or die thisfile . ": $CMD: $!"; + close $PH or die thisfile . ": $CMD: $!"; + return; + } + + # a bzip compressed file + } elsif ($file =~ /\.bz2$/) { + # Compress::Bzip2 + if (eval { require Compress::Bzip2; + import Compress::Bzip2 2.00; + import Compress::Bzip2 qw(bzopen); + 1; }) { + my ($FH, $bz); + open $FH, ">$file" or die thisfile . ": $file: $!"; + $bz = bzopen($FH, "wb9") or die thisfile . ": $file: $!"; + ($bz->bzwrite($content, length $content) == length $content) + or die thisfile . ": $file: " . $bz->bzerror; + $bz->bzclose and die thisfile . ": $file: " . $bz->bzerror; + return; + + # bzip2 executable + } else { + my ($PH, $CMD); + $CMD = whereis "bzip2"; + $CMD = "\"$CMD\" -9f > \"$file\""; + open $PH, "| $CMD" or die thisfile . ": $CMD: $!"; + print $PH $content or die thisfile . ": $CMD: $!"; + close $PH or die thisfile . ": $CMD: $!"; + return; + } + + # a plain text file + } else { + my $FH; + open $FH, ">$file" or die thisfile . ": $file: $!"; + print $FH $content or die thisfile . ": $file: $!"; + close $FH or die thisfile . ": $file: $!"; + return; + } +} + +# frwrite: A raw file writer +sub frwrite($$) { + local ($_, %_); + my ($file, $content, $FH); + ($file, $content) = @_; + + open $FH, ">$file" or die thisfile . ": $file: $!"; + binmode $FH or die thisfile . ": $file: $!"; + print $FH $content or die thisfile . ": $file: $!"; + close $FH or die thisfile . ": $file: $!"; + return; +} + +# runcmd: Run a command and return the result +sub runcmd($@) { + local ($_, %_); + my ($retno, $out, $err, $in, @cmd, $cmd, $OUT, $ERR, $STDOUT, $STDERR, $PH); + ($in, @cmd) = @_; + + $err = "Running " . join(" ", map "\"$_\"", @cmd) . "\n"; + $out = ""; + + open $STDOUT, ">&", \*STDOUT or die thisfile . ": STDOUT: $!"; + open $STDERR, ">&", \*STDERR or die thisfile . ": STDERR: $!"; + $OUT = tempfile or die thisfile . ": tempfile: $!"; + binmode $OUT or die thisfile . ": tempfile: $!"; + $ERR = tempfile or die thisfile . ": tempfile: $!"; + binmode $ERR or die thisfile . ": tempfile: $!"; + open STDOUT, ">&", $OUT or die thisfile . ": tempfile: $!"; + binmode STDOUT or die thisfile . ": tempfile: $!"; + open STDERR, ">&", $ERR or die thisfile . ": tempfile: $!"; + binmode STDERR or die thisfile . ": tempfile: $!"; + + $cmd = join " ", map "\"$_\"", @cmd; + if ($^O eq "MSWin32") { + open $PH, "| $cmd" or die thisfile . ": $cmd: $!"; + } else { + open $PH, "|-", @cmd or die thisfile . ": $cmd: $!"; + } + binmode $PH or die thisfile . ": $cmd: $!"; + print $PH $in or die thisfile . ": $cmd: $!"; + close $PH; + $retno = $?; + + open STDOUT, ">&", $STDOUT or die thisfile . ": tempfile: $!"; + open STDERR, ">&", $STDERR or die thisfile . ": tempfile: $!"; + + seek $OUT, 0, SEEK_SET or die thisfile . ": tempfile: $!"; + $out = join "", <$OUT>; + close $OUT or die thisfile . ": tempfile: $!"; + seek $ERR, 0, SEEK_SET or die thisfile . ": tempfile: $!"; + $err = join "", <$ERR>; + close $ERR or die thisfile . ": tempfile: $!"; + + return ($retno, $out, $err); +} + +# whereis: Find an executable +# Code inspired from CPAN::FirstTime +sub whereis($) { + local ($_, %_); + my ($file, $path); + $file = $_[0]; + return $WHEREIS{$file} if exists $WHEREIS{$file}; + foreach my $dir (path) { + return ($WHEREIS{$file} = $path) + if defined($path = MM->maybe_command(catfile($dir, $file))); + } + return ($WHEREIS{$file} = undef); +} + +# ftype: Find the file type +sub ftype($) { + local ($_, %_); + my $file; + $file = $_[0]; + return undef unless -e $file; + # Use File::MMagic + if (eval { require File::MMagic; 1; }) { + $_ = new File::MMagic->checktype_filename($file); + return "application/x-gzip" if /gzip/; + return "application/x-bzip2" if /bzip2/; + # All else are text/plain + return "text/plain"; + } + # Use file executable + if (defined($_ = whereis "file")) { + $_ = join "", `"$_" "$file"`; + return "application/x-gzip" if /gzip/; + return "application/x-bzip2" if /bzip2/; + # All else are text/plain + return "text/plain"; + } + # No type checker available + return undef; +} + +# flist: Obtain the files list in a directory +sub flist($) { + local ($_, %_); + my ($dir, $DH); + $dir = $_[0]; + @_ = qw(); + opendir $DH, $dir or die thisfile . ": $dir: $!"; + while (defined($_ = readdir $DH)) { + next if $_ eq "." || $_ eq ".." || !-f "$dir/$_"; + push @_, $_; + } + closedir $DH or die thisfile . ": $dir: $!"; + return join " ", sort @_; +} + +# prsrvsrc: Preserve the source test files +sub prsrvsrc($) { + local ($_, %_); + my ($dir, $DH); + $dir = $_[0]; + @_ = qw(); + opendir $DH, $dir or die thisfile . ": $dir: $!"; + while (defined($_ = readdir $DH)) { + next if $_ eq "." || $_ eq ".." || !-f "$dir/$_"; + push @_, $_; + } + closedir $DH or die thisfile . ": $dir: $!"; + rmtree "$dir/source"; + mkpath "$dir/source"; + frwrite "$dir/source/$_", frread "$dir/$_" + foreach @_; + return; +} + +# cleanup: Clean up the test files +sub cleanup($$$) { + local ($_, %_); + my ($r, $dir, $testno, $testname, $c); + ($r, $dir, $testno) = @_; + # Nothing to clean up + return unless -e $dir; + # Success + if ($r) { + rmtree $dir; + return; + } + # Fail - keep the test files for failure investigation + $testname = basename((caller)[1]); + $testname =~ s/\.t$//; + $c = 1; + $c++ while -e ($_ = "$dir.$testname.$testno.$c"); + rename $dir, $_ or die thisfile . ": $dir, $_: $!"; + return; +} + +# nofile: If we have the file type checker somewhere +sub nofile() { + $NOFILE = eval { require File::MMagic; 1; } + || defined whereis "file"? + 0: "File::MMagic or file executable not available" + if !defined $NOFILE; + return $NOFILE; +} + +# nogzip: If we have gzip support somewhere +sub nogzip() { + $NOGZIP = eval { require Compress::Zlib; 1; } + || defined whereis "gzip"? + 0: "Compress::Zlib or gzip executable not available" + if !defined $NOGZIP; + return $NOGZIP; +} + +# nobzip2: If we have bzip2 support somewhere +sub nobzip2() { + $NOBZIP2 = eval { require Compress::Bzip2; import Compress::Bzip2 2.00; 1; } + || defined whereis "bzip2"? + 0: "Compress::Bzip2 v2 or bzip2 executable not available" + if !defined $NOBZIP2; + return $NOBZIP2; +} + +# mkrndlog_existing: Create a random existing log file +sub mkrndlog_existing($$$@) { + local ($_, %_); + my ($mkrndlog, $dir, $filepat, @months, %contents); + ($mkrndlog, $dir, $filepat, @months) = @_; + + # Find a non-decided month and have an existing log + $_{$_[int rand @_]} = 1 if (@_ = grep !exists $_{$_}, @months) > 0; + # Find a non-decided month and not have an existing log + $_{$_[int rand @_]} = 0 if (@_ = grep !exists $_{$_}, @months) > 0; + # Decide the remain months randomly + $_{$_} = int rand 2 foreach grep !exists $_{$_}, @months; + %contents = qw(); + foreach my $m (@months) { + my ($file, $path); + $file = sprintf($filepat, $m); + $path = catfile($dir, $file); + if ($_{$m}) { + $contents{$file} = (&$mkrndlog($path, $m))[0]; + } else { + $contents{$file} = ""; + } + } + + return %contents; +} + +# mkrndlog_apache: Create a random Apache access log file +sub mkrndlog_apache($;$) { + local ($_, %_); + my ($file, $month, @logs, $content, @monrng, %months, $vardump, $tz); + ($file, $month) = @_; + + @logs = qw(); + + # Time zone + $tz = (-12 + (int rand 53) / 2) * 3600; + # To be removed + #$tz = -12 + (int rand 53) / 2; + #$tz = sprintf "%+05d", int($tz) * 100 + ($tz - int($tz)) * 60; + + # Get the range of a month + if (defined $month) { + @monrng = monrng_one $month; + # Get the range of some previous months + } else { + @monrng = monrng_rand; + } + for (my $i = 0; $i + 1 < @monrng; $i++) { + my $hosts; + # 2-5 hosts + $hosts = 2 + int rand 4; + # Generate the visit time of each host + for (my $j = 0; $j < $hosts; $j++) { + my ($host, $t, $user, $htver, @hlogs, $hlogs); + # Host type: 1: IP, 0: domain name + $host = int rand 2? randip: randdomain; + $t = $monrng[$i] + int rand($monrng[$i + 1] - $monrng[$i]); + $user = (0, 0, 1)[int rand 3]? "-": randword; + $htver = (qw(HTTP/1.1 HTTP/1.1 HTTP/1.1 HTTP/1.0))[int rand 4]; + # 3-5 log records for each host + $hlogs = 3 + int rand 3; + @hlogs = qw(); + while (@hlogs < $hlogs) { + my ($ttxt, $method, $url, $dirs, @dirs, $type, $status, $size); + # Time text + @_ = gmtime($t + $tz); + $_[5] += 1900; + $_[4] = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$_[4]]; + $ttxt = sprintf "%02d/%s/%04d:%02d:%02d:%02d %+05d", + @_[3,4,5,2,1,0], + int($tz / 3600) * 100 + ($tz - int($tz / 3600) * 3600) / 60; + + $method = (qw(GET GET GET HEAD POST))[int rand 5]; + + # Generate a random URL + # 0-3 levels of directories + $dirs = int rand 4; + @dirs = qw(); + push @dirs, "/" . randword while @dirs < $dirs; + $type = ("", qw(html html txt css png jpg))[int rand 7]; + if ($type eq "") { + $url = join("", @dirs) . "/"; + } else { + $url = join("", @dirs) . "/" . randword . ".$type"; + } + + $status = (200, 200, 200, 200, 304, 400, 403, 404)[int rand 8]; + if ($status == 304) { + $size = 0; + } else { + $size = 200 + int rand 35000; + } + push @hlogs, { + "time" => $t, + "record" => sprintf("%s - %s [%s] \"%s %s %s\" %d %d\n", + $host, $user, $ttxt, + $method, $url, $htver, $status, $size), + }; + + # 0-2 seconds later + $t += int rand 3; + } + push @logs, @hlogs; + # 0-5 seconds later + $t += int rand 6; + } + } + + # Sort by time + # A series of requests from a same host may run cross the next host + # So we need to sort again + @logs = sort { $$a{"time"} <=> $$b{"time"} } @logs; + + # Variables used, for failure investigation + $vardump = Data::Dumper->Dump([\@logs, $tz], [qw($logs $tz)]); + + # Split by months + %months = split_months @logs; + # Drop the time and keep the records + @logs = map $$_{"record"}, @logs; + # Insert 1-2 malformed lines + insert_malformed @logs; + + # Compose the content + $content = join "", @logs; + # Output the file + fwrite($file, $content); + # Return the content + return $content, $vardump, %months; +} + +# mkrndlog_syslog: Create a random Syslog log file +sub mkrndlog_syslog($;$) { + local ($_, %_); + my ($file, $month, @logs, $content, @monrng, %months, $vardump); + my (@hosts, $hosts); + ($file, $month) = @_; + + @logs = qw(); + + # 3-5 hosts + $hosts = 3 + int rand 3; + @hosts = qw(); + push @hosts, randword while @hosts < $hosts; + + # Get the range of a month + if (defined $month) { + @monrng = monrng_one $month; + # Get the range of some previous months + } else { + @monrng = monrng_rand; + } + for (my $i = 0; $i + 1 < @monrng; $i++) { + my (@mlogs, $mlogs, @t); + # 5-12 log records for each month + $mlogs = 5 + int rand 8; + @mlogs = qw(); + # Generate the time of each record + @t = qw(); + push @t, $monrng[$i] + int rand($monrng[$i + 1] - $monrng[$i]) + while @t < $mlogs; + foreach my $t (sort @t) { + my ($ttxt, $host, $app, $pid, $msg); + # Time text + @_ = localtime $t; + $_[5] += 1900; + $_[4] = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$_[4]]; + $ttxt = sprintf "%s %2d %02d:%02d:%02d", @_[4,3,2,1,0]; + $host = $hosts[int rand scalar @hosts]; + $app = (qw(kernel sendmail sshd su CRON), randword, randword)[int rand 5]; + # PID 2-65535 (PID 1 is init) + $pid = 2 + int rand 65533; + # 3-12 words for each message + $_ = 3 + int rand 10; + @_ = qw(); + push @_, randword while @_ < $_; + $msg = join " ", @_; + + push @mlogs, { + "time" => $t, + "record" => sprintf("%s %s %s[%d] %s\n", + $ttxt, $host, $app, $pid, $msg), + }; + } + push @logs, @mlogs; + } + + # Variables used, for failure investigation + $vardump = Data::Dumper->Dump([\@logs], [qw($logs)]); + + # Split by months + %months = split_months @logs; + # Drop the time and keep the records + @logs = map $$_{"record"}, @logs; + # Insert 1-2 malformed lines + insert_malformed @logs; + + # Compose the content + $content = join "", @logs; + # Output the file + fwrite($file, $content); + # Return the content + return $content, $vardump, %months; +} + +# mkrndlog_ntp: Create a random NTP log file +sub mkrndlog_ntp($;$) { + local ($_, %_); + my ($file, $month, @logs, $content, @monrng, %months, $vardump); + my ($pid, $peers, @peers, $refs, @refs); + ($file, $month) = @_; + + @logs = qw(); + + # PID 2-65535 (PID 1 is init) + $pid = 2 + int rand 65533; + # 3-5 peers + $peers = 3 + int rand 3; + @peers = qw(); + push @peers, randip while @peers < $peers; + # 2-3 references + $refs = 2 + int rand 2; + push @refs, randip while @refs < $refs; + + # Get the range of a month + if (defined $month) { + @monrng = monrng_one $month; + # Get the range of some previous months + } else { + @monrng = monrng_rand; + } + for (my $i = 0; $i + 1 < @monrng; $i++) { + my (@mlogs, $mlogs, @t); + # 5-12 log records for each month + $mlogs = 5 + int rand 8; + @mlogs = qw(); + # Generate the time of each record + @t = qw(); + push @t, $monrng[$i] + int rand($monrng[$i + 1] - $monrng[$i]) + while @t < $mlogs; + foreach my $t (sort @t) { + my ($ttxt, $type, $msg); + # Time text + @_ = localtime $t; + $_[5] += 1900; + $_[4] = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$_[4]]; + $ttxt = sprintf "%2d %s %02d:%02d:%02d", @_[3,4,2,1,0]; + # PID change - chance 2.73%, 50% change to total 25 records + $pid = 2 + int rand 65533 + if rand() < 0.0273; + $type = int rand 3; + # Type 0 - peer reachability + if ($type == 0) { + my ($peer, $events); + # 1-15 events + $events = 1 + int rand 15; + $peer = $peers[int rand @peers]; + # Reachable + if (int rand 5 > 1) { + $msg = "peer $peer event 'event_reach' (0x84) status 'unreach, conf, auth, $events events, event_reach' (0xe0f4)"; + # Unreachable + } else { + $msg = "peer $peer event 'event_unreach' (0x83) status 'unreach, conf, auth, $events events, event_unreach' (0xe0f3)"; + } + # Type 1 - reference host + } elsif ($type == 1) { + my ($refhost, $stratum); + $refhost = $refs[int rand @refs]; + # Stratum 2-4 + $stratum = 2 + int rand 2; + $msg = "synchronized to $refhost, stratum $stratum"; + # Type 2 - clock set + } elsif ($type == 2) { + my ($off, $freq, $err, $poll); + $off = (rand() - 0.5) / 10; + $freq = rand() * -10; + $err = rand() / 20; + # poll 4-10 + $poll = 4 + int rand 7; + $msg = sprintf "offset %8.6f sec freq %6.3f ppm error %8.6f poll %d", + $off, $freq, $err, $poll; + } + + push @mlogs, { + "time" => $t, + "record" => sprintf("%s ntpd[%d] %s\n", + $ttxt, $pid, $msg), + }; + } + push @logs, @mlogs; + } + + # Variables used, for failure investigation + $vardump = Data::Dumper->Dump([\@logs], [qw($logs)]); + + # Split by months + %months = split_months @logs; + # Drop the time and keep the records + @logs = map $$_{"record"}, @logs; + # Insert 1-2 malformed lines + insert_malformed @logs; + + # Compose the content + $content = join "", @logs; + # Output the file + fwrite($file, $content); + # Return the content + return $content, $vardump, %months; +} + +# mkrndlog_apachessl: Create a random Apache SSL engine log file +sub mkrndlog_apachessl($;$) { + local ($_, %_); + my ($file, $month, @logs, $content, @monrng, %months, $vardump); + my $host; + ($file, $month) = @_; + + @logs = qw(); + + $host = randdomain; + + # Get the range of a month + if (defined $month) { + @monrng = monrng_one $month; + # Get the range of some previous months + } else { + @monrng = monrng_rand; + } + for (my $i = 0; $i + 1 < @monrng; $i++) { + my (@mlogs, $mlogs, @t); + # 3-5 visitors for each month + $mlogs = 3 + int rand 3; + @mlogs = qw(); + # Generate the time of each record + @t = qw(); + push @t, $monrng[$i] + int rand($monrng[$i + 1] - $monrng[$i]) + while @t < $mlogs; + foreach my $t (sort @t) { + my ($ttxt, $pid, $remote, $priority, $child, $msg); + # Time text + @_ = localtime $t; + $_[5] += 1900; + $_[4] = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$_[4]]; + $ttxt = sprintf "%02d/%s/%04d %02d:%02d:%02d", @_[3,4,5,2,1,0]; + # PID 2-65535 (PID 1 is init) + $pid = 2 + int rand 65533; + # Remote client + $remote = randip; + # Child number + $child = int rand 15; + + # Error + if (int rand 5 == 1) { + $priority = "error"; + $msg = "SSL handshake failed (server $host:443, client $remote) (OpenSSL library error follows)"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + $msg = "OpenSSL: error:1408E0F4:SSL routines:SSL3_GET_MESSAGE:unexpected message"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + + # Info + } else { + $priority = "info"; + $msg = "Connection to child $child established (server $host:443, client $remote)"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + $msg = "Seeding PRNG with 1164 bytes of entropy"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + # 1: bad + if (int rand 2) { + $msg = "Spurious SSL handshake interrupt[Hint: Usually just one of those OpenSSL confusions!?]"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + # 2: success + } else { + my $reqs; + # 1-5 requests + $reqs = 1 + int rand 5; + for (my $j = 1; $j <= $reqs; $j++) { + if ($j == 1) { + $msg = "Initial (No.$j) HTTPS request received for child $child ($host:443)" + } else { + $msg = "Subsequent (No.$j) HTTPS request received for child $child ($host:443)" + } + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + } + $msg = "Connection to child $child closed with standard shutdown (server $host:443, client $remote)"; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s %05d] [%s] %s\n", + $ttxt, $pid, $priority, $msg), + }; + } + } + } + push @logs, @mlogs; + } + + # Variables used, for failure investigation + $vardump = Data::Dumper->Dump([\@logs], [qw($logs)]); + + # Split by months + %months = split_months @logs; + # Drop the time and keep the records + @logs = map $$_{"record"}, @logs; + # Insert 1-2 malformed lines + insert_malformed @logs; + + # Compose the content + $content = join "", @logs; + # Output the file + fwrite($file, $content); + # Return the content + return $content, $vardump, %months; +} + +# mkrndlog_modfiso: Create a random modified ISO 8861 date/time log file +sub mkrndlog_modfiso($;$) { + local ($_, %_); + my ($file, $month, @logs, $content, @monrng, %months, $vardump, $tz); + ($file, $month) = @_; + + @logs = qw(); + + # Time zone + $tz = (-12 + (int rand 53) / 2) * 3600; + # To be removed + #$tz = -12 + (int rand 53) / 2; + #$tz = sprintf "%+05d", int($tz) * 100 + ($tz - int($tz)) * 60; + + # Get the range of a month + if (defined $month) { + @monrng = monrng_one $month; + # Get the range of some previous months + } else { + @monrng = monrng_rand; + } + for (my $i = 0; $i + 1 < @monrng; $i++) { + my (@mlogs, $mlogs, @t); + # 5-12 log records for each month + $mlogs = 3 + int rand 3; + @mlogs = qw(); + # Generate the time of each record + @t = qw(); + push @t, $monrng[$i] + int rand($monrng[$i + 1] - $monrng[$i]) + while @t < $mlogs; + foreach my $t (sort @t) { + my ($ttxt, $id, $msg); + # Time text + @_ = gmtime($t + $tz); + $_[5] += 1900; + $_[4]++; + $ttxt = sprintf "%04d-%02d-%02d %02d:%02d:%02d %+05d", + @_[5,4,3,2,1,0], + int($tz / 3600) * 100 + ($tz - int($tz / 3600) * 3600) / 60; + # identity + $id = randword; + # 3-12 words for each message + $_ = 3 + int rand 10; + @_ = qw(); + push @_, randword while @_ < $_; + $msg = join " ", @_; + push @mlogs, { + "time" => $t, + "record" => sprintf("[%s] %s: %s\n", + $ttxt, $id, $msg), + }; + } + push @logs, @mlogs; + } + + # Variables used, for failure investigation + $vardump = Data::Dumper->Dump([\@logs, $tz], [qw($logs $tz)]); + + # Split by months + %months = split_months @logs; + # Drop the time and keep the records + @logs = map $$_{"record"}, @logs; + # Insert 1-2 malformed lines + insert_malformed @logs; + + # Compose the content + $content = join "", @logs; + # Output the file + fwrite($file, $content); + # Return the content + return $content, $vardump, %months; +} + +# monrng_one: Get the range of a specific month +sub monrng_one($) { + local ($_, %_); + my ($month, @range); + $month = $_[0]; + # Sanity check + return unless $month =~ /^(\d{4})(\d{2})$/; + @range = qw(); + # The beginning of the month + @_ = (0, 0, 0, 1, $2 - 1, $1 - 1900); + return unless defined($_ = timelocal(@_[0...6])); + push @range, $_; + # The beginning of the next month + $_[4]++; + if ($_[4] > 11) { + $_[4] = 0; + $_[5]++; + } + return unless defined($_ = timelocal(@_[0...6])); + push @range, $_; + return @range; +} + +# monrng_rand: Get the range of some previous months +sub monrng_rand() { + local ($_, %_); + my ($num, @range); + # 1-3 previous months + $num = 1 + int rand 3; + @range = qw(); + unshift @range, time; + @_ = (0, 0, 0, 1, (localtime)[4,5]); + unshift @range, timelocal(@_); + for (my $i = 0; $i < $num; $i++) { + $_[4]--; + if ($_[4] < 0) { + $_[4] = 11; + $_[5]--; + } + unshift @range, timelocal(@_); + } + return @range; +} + +# split_months: Split the log records by months +sub split_months(\@) { + local ($_, %_); + my ($logs, %months); + $logs = $_[0]; + + %months = qw(); + foreach (@$logs) { + my $month; + @_ = localtime $$_{"time"}; + $month = sprintf "%04d%02d", $_[5] + 1900, $_[4] + 1; + $months{$month} = "" if !exists $months{$month}; + $months{$month} .= $$_{"record"}; + } + + return %months; +} + +# insert_malformed: Insert 1-2 malformed lines +sub insert_malformed(\@) { + local ($_, %_); + my ($logs, $malformed); + $logs = $_[0]; + + $malformed = 1 + int rand 2; + while ($malformed > 0) { + my $line; + # Generate the random malformed line + $_ = 3 + int rand 5; + @_ = qw(); + push @_, randword while @_ < $_; + $line = join(" ", @_) . ".\n"; + $line =~ s/^(.)/uc $1/e; + # The position to insert the line + # The position cannot be 0 - or we cannot judge the log format + $_ = 1 + int rand(@$logs - 1); + $logs = [@$logs[0...$_], $line, @$logs[$_+1...$#$logs]]; + $malformed--; + } + + return; +} + +# randword: Supply a random English word +sub randword() { + local ($_, %_); + @_ = qw( +culminates spector thule tamil sages fasten bothers intricately librarian +mist criminate impressive scissor trance standardizing enabler athenians +planers decisions salvation wetness fibers cowardly winning call stockton +bifocal rapacious steak reinserts overhaul glaringly playwrights wagoner +garland hampered effie messy despaired orthodoxy bacterial bernardine driving +danization vapors uproar sects litmus sutton lacrosse); + return $_[int rand @_]; +} + +# randip: Supply a random IP +sub randip() { + return join ".", (int rand 255, int rand 255, + int rand 255, 1 + int rand 254); +} + +# randdomain: Supply a random domain +sub randdomain() { + local ($_, %_); + # Generate a random domain name + # 3-5 levels, end with net or com + $_ = 2 + int rand 3; + @_ = qw(); + push @_, randword while @_ < $_; + push @_, (qw(net com))[int rand 2]; + return join ".", @_; +} + +1; + +__END__