diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..c04e998 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,8 @@ +Version 2.0 + Rewritten the entire command line parsing code to get rid of the + PEAR Console_GetoptPlus dependency. + The script sould now be able to run out-of-the-box on most + machines without the need for Console_GetoptPlus. + +Version 1.0 + First version released! diff --git a/README b/README index 4d8f4af..6cb7672 100644 --- a/README +++ b/README @@ -8,12 +8,6 @@ This is a re-write of my previous check_md5 that was written in Bash. The Bash version is more tested and should work better. I wrote this this version mainly as a way to practice some PHP. -NOTE: For this script to work you need PEAR Console_GetoptPlus (or -Console_Getopt). -See http://pear.php.net/package/Console_GetoptPlus for more information on how -to install Console_GetoptPlus. - - Options: -h Print detailed help screen diff --git a/check_md5.php b/check_md5.php index 3923b89..c7d697f 100755 --- a/check_md5.php +++ b/check_md5.php @@ -1,8 +1,6 @@ #!/usr/bin/php # @@ -28,18 +26,13 @@ # Nagios plugin to monitor a single files MD5 sum. In case of mismatch # # the plugin exit with a CRICITAL error code. This behavior can be changed # # with the --warning argument. # -# Rewritten in PHP (depending on PEAR ConsoleGetopt. # +# Rewritten in PHP. # # # ############################################################################### -*/ -//include PEAR ConsoleGetopt -include ("Console/Getopt.php"); - - -$VERSION="1.0"; -$AUTHOR="(c) 2013 Jack-Benny Persson (jack-benny@cyberinfo.se)"; +$VERSION="2.0"; +$AUTHOR="(c) 2014 Jack-Benny Persson (jack-benny@cyberinfo.se)"; // Exit codes $STATE_OK=0; @@ -89,58 +82,38 @@ EOD; } -// Arguments and options (depending on PEAR ConsoleGetopt) -$options = new Console_Getopt(); - +// Command line parsing $shortoptions = "hV?"; -$longoptions = array("warning", "help", "version", "file=", "md5="); +$longoptions = array("warning", "help", "version", "file:", "md5:"); -$args = $options->readPHPArgv(); -$ret = $options->getopt($args, $shortoptions, $longoptions); +$options = getopt($shortoptions, $longoptions); -if (PEAR::isError($ret)) +if (isset($options['h']) || isset($options['?']) || isset($options['help'])) { - fwrite(STDERR,$ret->getMessage() . "\n\n"); - print_help(); - exit ($STATE_UNKNOWN); + print_help(); + exit ($STATE_OK); } -$opts = $ret[0]; - -if(sizeof($opts) > 0) +if (isset($options['V']) || isset($options['version'])) { - foreach($opts as $o) - { - switch($o[0]) - { - case 'h': - case '--help': - case '?': - print_help(); - exit ($STATE_OK); - break; - - case 'V': - case '--version': - print_version(); - exit ($STATE_OK); - break; - - case '--file': - $filename = $o[1]; - break; - - case '--md5': - $md5 = $o[1]; - break; - - case '--warning': - $warning = "yes"; - break; - } - } + print_version(); + exit ($STATE_OK); } +if (isset($options['file'])) +{ + $filename = $options['file']; +} + +if (isset($options['md5'])) +{ + $md5 = $options['md5']; +} + +if (isset($options['warning'])) +{ + $warning = "yes"; +} // Sanity checks if (empty($filename))