perl external command example
Thomas Guyot-Sionnest
dermoth at aei.ca
Wed Jan 28 19:56:28 CET 2009
-----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
More information about the Developers
mailing list