perl external command example
shadih rahman
shadhin71 at gmail.com
Thu Jan 29 02:51:39 CET 2009
Thanks for the suggestion Thomas. Its working fine now.
On Wed, Jan 28, 2009 at 6:56 PM, Thomas Guyot-Sionnest <dermoth at aei.ca>wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> shadih rahman wrote:
> > Can someone please give me an example how to submit external command
> > using perl script. I am trying to do this and its now working. The
> > command I am passing to named pipe is something like this. Thanks
> > "ACKNOWLEDGE_HOST_PROBLEM;
> > hostname;1;1;1;1;sr2690;testing
> > "1233162775
> >
> >
> > my code is like this.
> >
> >
> > #!/usr/bin/perl
> > #use strict;
> > #use Getopt::Long qw(:config no_ignore_case);
> > use warnings;
> > use Data::Dumper;
> >
> > use Getopt::Long ;
> >
> > my ($action, $host, $service, $username, $comment, $HELP);
> > my $now=`date +%s`;
> > chomp ( $now );
>
> # Easier/portable (you could also call time() directly in the printf
> below instead of using a variable):
>
> my $time = time()
>
> > my $commandfile='/var/log/nagios/rw/nagios.cmd';
> >
> > open CF, ">$commandfile" or die $!;
>
> I'd suggest opening the pipe only when you want to write to it, or at
> least after parsing the arguments. Ex. you could open and close it in
> the send_to_named_pipe function.
>
> >
> > [...]
> >
> > sub send_to_named_pipe {
> > my ($command ) = @_;
> > chomp ( $command );
> >
> > if ( defined ( $command ) ) {
> > print CF "\"$command\n\"$now";
>
> # I guess you meant something like this:
> printf CF "[%i] %s\n", $now, $command;
>
> >
> > [...]
> >
>
> Anyhow, if you're still stuck try outputing to a standard file, then
> compare the lines you get with known working commands.
>
>
> - --
> Thomas
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFJgKpc6dZ+Kt5BchYRAq2eAJ9L+1+ssz+ntkmGFRY/mrbD2XLdQgCgpZGl
> qCsSxMrK30Kg6ydRqDwGefQ=
> =eRMt
> -----END PGP SIGNATURE-----
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Nagios-devel mailing list
> Nagios-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-devel
>
--
Cordially,
Shadhin Rahman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20090129/36303490/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list