#!/usr/local/bin/perl # # Name: # # # Synopsis # # # Options # # # History: # # Usefull Values. use Sys::Syslog qw( :DEFAULT setlogsock); $BASENAME = $0; $BASENAME =~ s|\\|/|g; if ($BASENAME =~ m|(.*/)(.*)|) { $BASENAME = $2; } # # code here. while ($#ARGV > -1) { $_ = shift @ARGV; if (/^--DEBUG$/) { $DEBUG=1; &debug("Debugging on"); next; } if (/^--HELP$/) { &usage("__SHOW_HELP"); } &usage("$_"); } # # display the help message. # I find it usefull to leave this subroutine here, next to the parameter # parsing, as it makes it much easer to keep the help and the # actual parsing in sync. sub usage { $gripe=shift @_; print <<"EO_USAGE"; $BASENAME --HELP print this screen EO_USAGE exit 0 if ($gripe eq "__SHOW_HELP"); &die("Don't understand:$gripe"); } # # an easy way to change those back-ticks into # system() calls when we fuck up. sub doThis { local ($result); local ($thing) = pop @_; &debug("doing [$thing]"); # $result=system($thing); $result = `$thing`; &debug("finished shelling; output:\n$result"); &debug("output ends"); return $result; } # # Log something to the local syslog sub logItem { local ($message); $message = pop(@_); setlogsock('unix'); openlog($BASENAME,'','user'); syslog('info',$message); closelog; } # # A (braindead) undertaker. sub die { local ($gripe); $gripe = pop(@_); &warn("fatal:$gripe"); &logItem("fatal:$gripe"); exit 1; } # # A (braindead) friend for our undertaker. sub warn { local ($gripe); $gripe = pop(@_); print STDERR "$BASENAME:$gripe\n"; &logItem($gripe); } # # A simple debug outputer. sub debug { local ($gripe); $gripe = pop(@_); $DEBUG && print STDERR "DEBUG:$gripe\n"; }