Sponsored Content
Top Forums Shell Programming and Scripting What is wrong with my perl script? Post 302584169 by SkySmart on Thursday 22nd of December 2011 10:13:35 AM
Old 12-22-2011
What is wrong with my perl script?

i managed to write a perl script for nagios. now, the script works. but i think there's somethign wrong with the exit codes. because the script doesn't show the output of the results in nagios, it instead shows null.

please tell me what i'm doing wrong here:

Code:
#!/usr/local/bin/perl

use STUN::Client;
use Data::Dumper;
use Getopt::Long;
use warnings;
use strict;

my %ERRORS = ( OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 );

my $timeout = 30;

$SIG{ ALRM } = sub {
   print "CRITICAL: Timeout expired (${timeout}s) before server responded.";
   exit $ERRORS{ CRITICAL };
};

my $server = $ARGV[0];

my $userip = $ARGV[1];

my $stun_client = STUN::Client->new;

$stun_client->stun_server("$userip");

my $r = $stun_client->get;

if ($r eq '')
{
   print "CRITICAL:  Did not receive a response from the device = [ $server, $userip ]\n";
   exit $ERRORS{CRITICAL};
}

my $ip = $r->{ma_address};

my $transid = $r->{transaction_id};

my $portreturned = $r->{ma_port};

# Split the IP address into an array of octets

my @x = split /\./, $ip;
 
# Print it unless it is invalid


if (($#x != 3 or grep {$_ =~ /\D/ or $_ < 0 or $_ > 255} @x) && ($transid eq '') && ($portreturned eq ''))

{

   print "CRITICAL:  IP returned is not a public IP. Response from query  ==  IP [ $ip ], TranID [ $transid ], Port [ $portreturned ].\n";
   exit $ERRORS{CRITICAL};
}

else

{

   print "OK: Response received from device [ $server ] is sufficienct  ==  IP [ $ip ], TranID [ $transid ], Port [ $portreturned ].\n";
   exit $ERRORS{OK};
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl regexp error , I cant understand what is wrong

perl regexp error , I cant understand what is wrong Hello all I have simple perl regexp that is searching for pattern in string and replace it with the same string + addition string here is what I have : my $rec = q| new Array("Attributes Management" ... (4 Replies)
Discussion started by: umen
4 Replies

2. Shell Programming and Scripting

What's wrong with this script

I am trying to create a script but it is giving me errors on Cygwin for the following script. Could someone tell me, what am I doing wrong? choice=1000 echo "choice is $choice" while ; do echo "choice is $choice" echo 'Please select your option:' echo '1. Option 1' echo '2. Option 2'... (3 Replies)
Discussion started by: amitg1980
3 Replies

3. UNIX for Dummies Questions & Answers

what is wrong with this script?

Hi, I have this example script which gives error ": unexpected operator/operand". I need the '' brackets for operator precedence. #!/bin/ksh x="abc" y="xyz" z="123" if -a then print "yes" else print "no" fi Thanks (2 Replies)
Discussion started by: rs1969
2 Replies

4. Shell Programming and Scripting

Perl Script issue. What am I doing wrong?

#!/usr/local/bin/perl open (MYFILE, 'logs_report'); while (<MYFILE>) { $rec=$_; chomp ($rec); @arr=split(/ /,$rec); print $rec,"\n" if ($arr!~/OK/); open (MYF, '>data.txt'); print $rec,"\n" if ($arr!~/OK/); close (MYF); (14 Replies)
Discussion started by: SkySmart
14 Replies

5. Shell Programming and Scripting

whats wrong with this line using perl

E:\>perl -00ne 'push @a,"$_\0$ARGV\n";END{print reverse split/\0/ for sort @a}' file1-obj_prof.out.txt file2-obj_prof.out.txt' Can't find string terminator "'" anywhere before EOF at -e line 1. (6 Replies)
Discussion started by: richsark
6 Replies

6. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies

7. Shell Programming and Scripting

Perl...getting wrong output?

Good morning! Im trying to write and learn at the same time a simple script. fTHe script should tell me if a number is odd or even/ #!/usr/bin/perl $num = 10; $string1 = "This number is odd"; $string2 = "This number is even"; if ($num /= 2) { print "$string1\n"; }else{ ... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

9. UNIX for Dummies Questions & Answers

Perl find & replace - what am I doing wrong?

Hi! I have a directory full of .plist type files from which I need to delete a line. Not every file contains the line, but of course I'd like to do it recursively. The line which I want to delete is: <string>com.apple.PhotoBooth</string> and looks like this in its native habitat: ... (9 Replies)
Discussion started by: sudon't
9 Replies

10. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x foo.pl and then when i try to run it : ./foo.pl im getting this error: ./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies
LUCKYBACKUP(8)						      System Manager's Manual						    LUCKYBACKUP(8)

NAME
luckybackup - a powerful, fast and reliable backup & sync tool SYNOPSIS
luckybackup [OPTIONS]... [FILE]... DESCRIPTION
luckybackup is an application that backs-up and/or synchronizes any directories with the power of rsync OPTIONS
--help displays this help message --version displays the current version of the application --skip-critical does not execute tasks that appear with a 'CRITICAL' warning message --dry-run executes luckybackup in dry-run (simulation) mode --silent executes luckybackup in silent mode (just tray notification icon shown) -c console mode. Use this, if there is no graphical envrironment available --no-questions skips confirmation questions asked to user. Implies -c (console mode) [FILE] is the filename of the already created profile that is going to be executed examples 1. Execute luckybackup gui : $ luckybackup 2. Execute luckybackup in silent mode for profile '~/.luckyBackup/profiles/BackupHome.profile' : $ luckybackup --silent ~/.luckyBackup/profiles/BackupHome.profile 3. Execute luckybackup in console mode for profile '~/.luckyBackup/profiles/BackupHome.profile' : $ luckybackup -c BackupHome.profile 4. Execute luckybackup in console mode for profile '~/.luckyBackup/profiles/BackupHome.profile' Do not ask any questions and skip all operations that appear CRITICAL after the checks : $ luckybackup --skip-critical --no-questions ~/.luckyBackup/profiles/BackupHome.profile SEE ALSO
For a complete documentation, please have a look at the application manual via the gui main window help menu. AUTHOR
luckybackup was written by <Loukas Avgeriou>. This manual page was written by luckyb <luckyb69@sourceforge.net>, for the Debian project (but may be used by others). 2011-01-12 LUCKYBACKUP(8)
All times are GMT -4. The time now is 09:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy