Sponsored Content
Top Forums Shell Programming and Scripting Understanding of a script as a scripting newbie Post 302353299 by locutus01 on Tuesday 15th of September 2009 05:17:49 AM
Old 09-15-2009
Understanding of a script as a scripting newbie

Hi!

I have the following script and do not understand part of it. I have a very little understanding of scripting.

The script is for Nagios to check the response of fast-com.de. The guy who has written it is no longer in the company.

Code:
#!/bin/sh

PATH=/adm/bin:/bin:/usr/bin
export PATH

. /adm/libexec/nagios/utils.sh

print_help() {
}

print_usage() {
}


status_out=/tmp/sms-status.out
thresh_warn=5000
thresh_crit=15000
host=www.fast-com.de
url=/gsm/status.php


while test -n "$1"; do
  case "$1" in
    --help|-h)
      print_help
      exit $STATE_OK
      ;;
    --version|-V)
      print_revision
      exit $STATE_OK
      ;;
    --warning|-w)
      thresh_warn=$2
      shift
      ;;
    --critical|-c)
      thresh_crit=$2
      shift
      ;;
    --host|-H)
      host=$2
      shift
      ;;
    --url|-u)
      url=$2
      shift
      ;;
    *)
      $ECHO "Unknown argument: $1"
      print_usage
      exit $STATE_UNKNOWN
      ;;
  esac
  shift
done


rm -f $status_out
t=$(time 2>&1 -p wget --quiet --post-data='username=xxxxxx&password=xxxx&id=xxxxx' --no-check-certificate --output-document=$status_out --timeout=30 "https://${host}${url}" | perl -ne 'print int($1 * 1000) if /^real (\S+)/')

if [ ".$t" != . ]; then
  if [ -s $status_out ]; then
    result="ok"
    exitstatus=$STATE_OK
    if [ $t -ge $thresh_warn ]; then
      result="warning"
      exitstatus=$STATE_WARNING
    fi
    if [ $t -ge $thresh_crit ]; then
      result="critical"
      exitstatus=$STATE_CRITICAL
    fi
  else
    result="critical"
    exitstatus=$STATE_CRITICAL
  fi
else
  result="critical"
  exitstatus=$STATE_CRITICAL
fi

echo "REQUEST $result - $t ms | rtt=$t"
exit $exitstatus

What i don't understand are the following parts:

1. if [ ".$t" != . ]; then
I know that is a not equal check, but .$t and . ?

2. if [ -s $status_out ]; then
Here i don't know the meaning of -s

3. if [ $t -ge $thresh_warn ]; then
What does the -ge do here? I would expect something like $t -xy=xx

The check is delivering a status "Critical" and when i don't understand this three parts i can not verify the values which are delivered.

Thx

Alex

Last edited by locutus01; 09-15-2009 at 06:26 AM.. Reason: Tag failure
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell Scripting Newbie

I'm relatively new at this scripting game, just need to learn some basic stuff for data handling. My current need is to write a script that loops through a textfile of filenames, and for each file removes the first line and re-writes that file to a new name. In fact I could do with knowing... (1 Reply)
Discussion started by: mattyjim2
1 Replies

2. Shell Programming and Scripting

Scripting Newbie

Seems simple but I am having difficulty with this one: I am trying to write a single command line argument (which will be a path) - the program should print out the owner of the path. I can not get anything I write to run. Please help. (5 Replies)
Discussion started by: Kymmers7
5 Replies

3. Shell Programming and Scripting

scripting newbie needs help

I have written a script that will email a generic user when a device is "offline". I would like to enhance this by having the script lookup a contact's email and automatically add it to the MAIL_LIST. I am trying to lookup and return data based on a field common in two files File 1 ... (0 Replies)
Discussion started by: irishluck66
0 Replies

4. UNIX for Dummies Questions & Answers

am a newbie to unix. plz help in understanding this code.

hi everybody. please help me in understanding this code. echo "************* starting job on `date +\"%d/%m/%Y at %T\"` **************" # scriptdir=`dirname $0` . ${scriptdir}/env_params.sh # SHLIB_PATH=${ORACLE_HOME}/lib: export SHLIB_PATH export... (1 Reply)
Discussion started by: gokulj
1 Replies

5. Shell Programming and Scripting

scripting newbie... some help please?

hi all, i am just getting in to bash scripting, so don't be too harsh... i've created this little backup script, and it's just awfull... ugly, doesn't work like I want it to, the works. anyways, i was hoping some of you might help me improve it and learn a little in the process. what i... (13 Replies)
Discussion started by: jmd9qs
13 Replies

6. Shell Programming and Scripting

Understanding Shell Scripting

Hi Gurus, Im new to Shell scripting. I have a shell script which basically sends an email when called thorugh my ETL tool. Wanted to understand the its functionality in detail. Would be great it any one can explain what exactly the commands to #!/bin/sh # Dummy UUCP rmail command for... (1 Reply)
Discussion started by: r_t_1601
1 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Need help understanding ksh scripting.

Can any one please tell me where the error in below script. Output is not as per my requirement. if condition not comparing the result of record count of a file with 1. where is the pbm in my script? Appreciate your help.. #!/bin/ksh #Module- #Summary- To move the file to direcotries if... (9 Replies)
Discussion started by: shivadanam
9 Replies

8. Shell Programming and Scripting

Trouble understanding shell scripting (mostly wsname)

Am still learning Scripting and I come across a build command that I don't really understand if /local/bin/wsname 2>/dev/null; then base="`/local/bin/wsname`" export base fi if ; then /local/bin/wsname exit 1 fi WSNAME="$base"/ can some one in light me to what... (1 Reply)
Discussion started by: Wpgn
1 Replies

9. Shell Programming and Scripting

Bash scripting - Newbie

Hi all, I have drill to do and I'll very appreciate your help: Please create a simple CSV file as follow (3 columns and 4 rows): A,B,C A,”B,C”,D “A,B”,C,D o A,B,”C,D” - Please refer to the comma between the quotation marks as a parameter and not as a separator. - Please provide... (3 Replies)
Discussion started by: elior
3 Replies

10. Shell Programming and Scripting

Understanding Tetris-game code. newbie

Hi All, Been trying to understand the code in tetris game (in the sticky threads) & i know i have a alot reading /practice to do. it's using advanced methods with arrays and arithmetic and would much appreciate if some one can guide me to good books that's not outdated that would help me take... (0 Replies)
Discussion started by: xcod3r
0 Replies
Nagios::Plugin::Functions(3pm)				User Contributed Perl Documentation			    Nagios::Plugin::Functions(3pm)

NAME
Nagios::Plugin::Functions - functions to simplify the creation of Nagios plugins SYNOPSIS
# Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default use Nagios::Plugin::Functions; # nagios_exit( CODE, $message ) - exit with error code CODE, # and message "PLUGIN CODE - $message" nagios_exit( CRITICAL, $critical_error ) if $critical_error; nagios_exit( WARNING, $warning_error ) if $warning_error; nagios_exit( OK, $result ); # nagios_die( $message, [$CODE] ) - just like nagios_exit(), # but CODE is optional, defaulting to UNKNOWN do_something() or nagios_die("do_something() failed horribly"); do_something_critical() or nagios_die("do_something_critical() failed", CRITICAL); # check_messages - check a set of message arrays, returning a # CODE and/or a result message $code = check_messages(critical => @crit, warning => @warn); ($code, $message) = check_messages( critical => @crit, warning => @warn, ok => @ok ); # get_shortname - return the default short name for this plugin # (as used by nagios_exit/die; not exported by default) $shortname = get_shortname(); DESCRIPTION
This module is part of the Nagios::Plugin family, a set of modules for simplifying the creation of Nagios plugins. This module exports convenience functions for the class methods provided by Nagios::Plugin. It is intended for those who prefer a simpler functional interface, and who do not need the additional functionality of Nagios::Plugin. EXPORTS Nagios status code constants are exported by default: OK WARNING CRITICAL UNKNOWN DEPENDENT as are the following functions: nagios_exit nagios_die check_messages The following variables and functions are exported only on request: %ERRORS %STATUS_TEXT get_shortname max_state max_state_alt FUNCTIONS The following functions are supported: nagios_exit( <CODE>, $message ) Exit with return code CODE, and a standard nagios message of the form "PLUGIN CODE - $message". nagios_die( $message, [CODE] ) Same as nagios_exit(), except that CODE is optional, defaulting to UNKNOWN. NOTE: exceptions are not raised by default to calling code. Set $_use_die flag if this functionality is required (see test code). check_messages( critical => @crit, warning => @warn ) Convenience function to check a set of message arrays and return an appropriate nagios return code and/or a result message. Returns only a return code in scalar context; returns a return code and an error message in list context i.e. # Scalar context $code = check_messages(critical => @crit, warning => @warn); # List context ($code, $msg) = check_messages(critical => @crit, warning => @warn); check_messages() accepts the following named arguments: critical => ARRAYREF An arrayref of critical error messages - check_messages() returns CRITICAL if this arrayref is non-empty. Mandatory. warning => ARRAYREF An arrayref of warning error messages - check_messages() returns WARNING if this arrayref is non-empty ('critical' is checked first). Mandatory. ok => ARRAYREF | SCALAR An arrayref of informational messages (or a single scalar message), used in list context if both the 'critical' and 'warning' arrayrefs are empty. Optional. join => SCALAR A string used to join the relevant array to generate the message string returned in list context i.e. if the 'critical' array @crit is non-empty, check_messages would return: join( $join, @crit ) as the result message. Optional; default: ' ' (space). join_all => SCALAR By default, only one set of messages are joined and returned in the result message i.e. if the result is CRITICAL, only the 'critical' messages are included in the result; if WARNING, only the 'warning' messages are included; if OK, the 'ok' messages are included (if supplied) i.e. the default is to return an 'errors-only' type message. If join_all is supplied, however, it will be used as a string to join the resultant critical, warning, and ok messages together i.e. all messages are joined and returned. get_shortname Return the default shortname used for this plugin i.e. the first token reported by nagios_exit/nagios_die. The default is basically uc basename( $ENV{NAGIOS_PLUGIN} || $0 ) with any leading 'CHECK_' and trailing file suffixes removed. get_shortname is not exported by default, so must be explicitly imported. max_state(@a) Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN, DEPENDENT The typical usage of max_state is to initialise the state as UNKNOWN and use it on the result of various test. If no test were performed successfully the state will still be UNKNOWN. max_state_alt(@a) Returns the worst state in the array. Order is: CRITICAL, WARNING, UNKNOWN, DEPENDENT, OK This is a true definition of a max state (OK last) and should be used if the internal tests performed can return UNKNOWN. SEE ALSO
Nagios::Plugin; the nagios plugin developer guidelines at http://nagiosplug.sourceforge.net/developer-guidelines.html. AUTHORS
This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net COPYRIGHT AND LICENSE
Copyright (C) 2006 by Nagios Plugin Development Team This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-12-23 Nagios::Plugin::Functions(3pm)
All times are GMT -4. The time now is 11:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy