How to avoid return code of 141?

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Infrastructure Monitoring How to avoid return code of 141?
# 1  
Old 01-12-2011
How to avoid return code of 141?

I have a script that logins into a Cisco switch via SSH and does a ping to another IP. This script is used as a check for nagios. I only want an exit codes of either 2, 1, 0 for fail, warn, ok, respectively. However, when I implement this code in nagios, I sometimes get a return code of 141. Is there some way I can avoid this?

Code:
#!/usr/bin/perl
#
# Use: usr/local/sbin/check_cisco_ping_ssh <host> <port> <user> <pass> <ip> <warn> <crit>
#
#use strict;

use Net::SSH::Perl;

$ENV{'HOME'} = '/var/lib/nagios';

my $router=$ARGV[0];
my $port=$ARGV[1];

my $user=$ARGV[2];
my $pass=$ARGV[3];

my $ip=$ARGV[4];

my $warn=$ARGV[5];
my $crit=$ARGV[6];


my $sesion_ssh = Net::SSH::Perl->new($router, protocol=>1,2, cipher=>'DES', port=>$port, debug=> 'false', use_pty=>0);
$sesion_ssh->login($user, $pass);

my $command="ping $ip";

my($output, $output_error, $value_exit) = $sesion_ssh->cmd($command);

$output =~ /Success rate is (\d*) (.*)/;

my $rate=$1;

if ( $rate <= $crit ) {
        print "PROBLEM: $ip is DOWN Rate=$rate%\n";
        exit(2);
}

if ( $rate <= $warn ) {
        print "WARNING: $ip is at Rate=$rate%\n";
        exit(1);
}

if ( $rate <= 100 ) {
        print "OK: $ip is UP Rate=$rate%\n";
        exit(0);
}

exit(3);

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Avoid carriage return until ^M is found (CentOS 6, bash 4.1)

Hi everyone, I have the following contents in a text file (as seen when viewed using vim): one two three ^M four five six ^M seven eight nine ^M ten eleven twelve ^M (That is just a small portion of the file) How can I obtain the following result? one two three ^M four five six ^M seven... (2 Replies)
Discussion started by: gacanepa
2 Replies

2. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

3. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

4. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

5. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

6. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

7. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question