update:#!/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;
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)
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |