Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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;"


In reply to (crazyinsomniac) Re: SysLogger by crazyinsomniac
in thread SysLogger by Rex(Wrecks)

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (12)
    As of 2015-07-29 21:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (269 votes), past polls