Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

(crazyinsomniac) Re: SysLogger

by crazyinsomniac (Prior)
on Aug 02, 2001 at 09:26 UTC ( #101579=note: print w/ replies, xml ) Need Help??


in reply to SysLogger

No real improvements, just a matter of style
(Dammit Jim, this is not C ;-) yeah i know, TIMTOWTDI)

#!/usr/bin/perl -w ############################################################### # Script for logging automation to a Syslog server # # For public use, creator takes no responsibilities for # # any damages, misconfigs or loss of sanity resulting from # # these script(s) # ############################################################### use strict; use Net::Ping; use Net::Syslog; use Getopt::Std; use vars qw($opt_p $opt_t $opt_m); #Set an array with legal Priority values my @priVals = qw(emerg alert crit err warning notice info debug); getopts('m:p:t:'); # I prefer &getopts('f?h:u:p:', \%O) because it doesn't # set additional global vars like described in pod unless ( defined $opt_p && defined $opt_t ) { die(<<' THEOPTIONS'); Missing Options! Required: -p <proirity of message> Can be emerg, alert, crit, err, warning, notice, info, debug -t <text of Message to syslog> Note: If you use spaces in your message, surround the message in q +uotes -m <machine name or IP> Note: this is optional, default is 127.0.0.1 THEOPTIONS } $opt_m = "127.0.0.1" unless defined $opt_m; my $pingResult = Net::Ping->new('icmp'); die ("\nSysLoggerErr:1\nCannot resolve $opt_m\n") unless $pingResult->ping($opt_m); $pingResult->close() ; for my $priV (@priVals) { last if $opt_p eq $priV; die ("Not a valid Priority, check caps as this is case sensitive!\ +n") if $priV eq 'debug'; next if $opt_p ne $priV; } my $syslog = new Net::Syslog(SyslogHost => $opt_m, Facility => 'syslog', Priority => $opt_p); $syslog->send("$opt_t\n") ; exit;
update:
<<' THEOPTIONS' is called a heredoc, just do a search on this site and you'll find plenty of info (and you can always query the faq from perldoc)

f? was just an example from xml_pimp and f? does nothing special, it just mean there is a switch called f, and one called ? (which is help in xml_pimp)

As for the info, it's all documentation for Getopt::Std

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


Comment on (crazyinsomniac) Re: SysLogger
Download Code
Re: (crazyinsomniac) Re: SysLogger
by Rex(Wrecks) (Curate) on Aug 02, 2001 at 09:44 UTC
    Hmmm, I like the "C" sytle :) It helps me read all of my code as I write C as well. But I'm sure I could argue about that all day.

    Where do I get info on what you suggested with the getopts line? Specificly, what does the f? do?
    I'm also curious to look up the trick that you used with THEOPTIONS...interesting.

    I really like perl, and the comunities seem very helpful as well.
    Thanks

    Rex(Wrecks)
    =========
    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://101579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-08-01 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls