|
NAMEUnix::Lsof::Result - Perlish interface to lsof outputVERSIONThis document describes Unix::Lsof::Result version 0.1.0SYNOPSISuse Unix::Lsof; my $lr = lsof("-p",$$); if ($lr->has_errors()) { print qq(Errors encountered: $lr->errors()); } my @pids = $lr->get_pids(); my @file_types = $lr->get_values( "file type" ); my $access_modes = $lr->get_values( "access mode" ); # Print out file name and type my @filenames = $lr->get_arrayof_rows( "file type", "file name" ); for my $p (@filenames) { print "File type: $p->[0] - File name: $p->[1]\n"; } # Print a list of open IPv4 connections my %filetype = $lr->get_hashof_rows( "file type", "n", "protocol name" ); for my $conn ( @{ $filetype{"IPv4"} } ) { print qq(IPv4 connection to: $conn->{"n"}, protocol: $conn->{"protocol name"}\n); } # Print out a list of open files larger than 1kb my @filesize = $lr->get_arrayof_columns( "file name", "file size" ); for my $i ( 0..scalar( @{ $filesize[1] } ) ) { if ( $filesize[1][$i] >= 1024 ) { print "File $filesize[0][$1] is over 1k\n"; } } # Print out the size of text files found my $fs = $lr->get_hashof_columns( "file name", "file size" ); for my $i ( 0..scalar( @{ $fs->{"file name"} } ) ) { if ( $fs->{"file name"}[$i] =~ m/\.txt\z/ ) { print qq(Found $fs->{"file size"}[$i] bytes large text file\n); } } # The same as previous, using filters my @file_list = $lr->get_values( { "file name" => qr/\.txt\z/ }, "file size" ); for my $f (@file_list) { print qq(Found $f bytes large text file); } # Looking for text files between 1 and 4k my @file_list = $lr->get_filenames( { "file name" => qr/\.txt\z/, "file size" => sub { $_[0] > 1024 && $_[0] <= 4096 } }, "file name"); DESCRIPTIONThis module offers multiple ways of organising and retrieving the data returned by lsof. It attempts to make it as easy as possible for the user to obtain the information he wants in the way he wants it.The "Unix::Lsof::Result" object is returned when calling "<Unix::Lsof-"lsof()>> in scalar context. When evaluated in boolean context the object will evaluate to true unless no STDOUT output is obtained from running the "lsof" binary <b>and </b> STDERR output was obtained from the same run. This allows for the following logic : if ($lf = $lsof(@params)) { # we got output or no errors, some success was had warn "Errors: ".$lf->errors() if $lf->has_errors(); # normal processing continues # ... } else { # no output and we have an error message, something is badly wrong die "Errors: ".$lf->errors(); } Note that you will only find out whether any errors were encountered by examining the "has_errors" return value, examining truth of the object itself only makes sense if you just care about some valid output being returned (e.g. if you're passing in a list of files, some of which may not exist). All of the output accessor methods (i.e. the methods starting with "get_", for example "get_values", "get_arrayof_rows") have the following properties:
INTERFACEMethods
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENTUnix::Lsof::Result requires no configuration files or environment variables.DEPENDENCIESUnix::Lsof::Result requires the following modules:
INCOMPATIBILITIESNone reported.BUGS AND LIMITATIONSPlease report any bugs or feature requests to "bug-unix-lsof@rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Unix-Lsof>.No bugs have been reported so far. As with "Unix::Lsof", there are a number of improvements that could be made to this module, particularly with regards to filtering. Further development is almost certainly strictly "develop by bugreport", so if you want a feature added, please open a wishlist item in the RT web interface and let me know. I'm more than happy to do more work on this module, but want to see what concrete improvements people would like to have. As always, patches are more than welcome. ACKNOWLEDGEMENTSA very heartfelt thanks to Vic Abell for writing "lsof", it has been invaluable to me over the years. Many thanks as always to http://www.perlmonks.org, the monks continue to amaze and enlighten me. A very special thanks to Damian Conway, who (amongst other things) recommends writing module documentation at the same time as code (in his excellent book "Perl Best Practices"). I didn't follow that advice and as a result writing these docs was more painful and error-prone than it should have been. Please Mr. Conway, for the next edition could you put more emphasis on that recommendation so that dolts like me get it the first time?AUTHORMarc Beyer "<japh@tirwhan.org>"LICENCE AND COPYRIGHTCopyright (c) 2008-2013,2009, Marc Beyer "<japh@tirwhan.org>". All rights reserved.This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTYBECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "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 SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (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 SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Visit the GSP FreeBSD Man Page Interface. |