#!/usr/bin/perl -w # # Copyright (c) 2001 Dominic Mitchell. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # @(#) $Id: psg.pl,v 1.3 2001/12/06 09:59:14 dom Exp $ # =head1 NAME psg - ps piped into grep =head1 SYNOPSIS psg [B<-a> psargs] [B<-c> pidcol] search =head1 DESCRIPTION psg runs the ps(1) command, and greps the output for anything listed on the command line. It will never list itself in the output. psg will print out a header line indicating what columns are what. =head1 OPTIONS =over 4 =item B<-a> I Sets the arguments to run ps with. Defaults to I. =item B<-c> I Sets the column which the pid is listed. Defaults to 1. At present, this is only used to get rid of the line for psg from the output. =back =head1 SEE ALSO grep(1), ps(1). =head1 AUTHOR Dominic Mitchell Edom@happygiraffe.netE =cut use strict; use Getopt::Std; sub usage { die "usage: $0 [-a psargs] [-c pidcol] string\n"; } my %opt; getopts("a:c:", \%opt) or usage; my $pidcol = $opt{c} || 1; my $psargs = $opt{a} || "ax"; open PS, "ps $psargs |"; my $header = ; my $pid; my $foundone = 0; while () { if (m/$ARGV[0]/o) { $pid = (split)[ $pidcol - 1 ]; next if $pid eq $$; print $header unless $foundone++; print; } }